Windows and Mac OS will have one too, but I don’t know what they are called. How you do that depends on which OS you have. When you have a task that needs to be repeated according to some schedule (once a day, once a month, once an hour, etc) the best solution is not to program the schedule yourself, but to leave it to the OS. If you reboot your computer, your script will stop running and your scheduled task will not run. The problem is that your script will need to run for weeks or months at a time, and for 99.99% of that time it’s just doing nothing. In my case I have to have something done once every 24 hours.Ī while loop is not the best solution for this. The code before the while loop runs, then the while loop repeats the inner block until the condition x > 0 is false, then the code after the loop runs.Ĭode after the loop will never run if the while loop never completes. Time.sleep(1) # Pause for 1 second (not 1 day!) It does that until the while condition is false, when it jumps to just past the loop. Then it runs the lines of code inside the while loop and jumps back to the beginning of the loop. If you start at the top of the script, and imagine the interpreter doing whatever you tell it to do in line 1, line 2, line 3 etc until you reach a while loop. In simple terms, Python runs one line of code at a time. The while loop does not effect code outside the loop except that changes to variables and data inside the loop will be seen outside the loop.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |