will be helpful for those in need I'm making a countdown clock, and I've got the basics down, but I have trouble trying to have a variable go down 1, every second. So here is an example: , Use the time module?
x = 100
while x > 0:
wish helps you your problem is that by using the eg.enterbox function, the numbers the user inputs will be seen as strings. To fix this, we send the 'string' the enterbox returns, to the int() function. This will translate the string of numbers to an actual integer that can be used to subtract other integers. eg.
enter = "3"
enter = int(enter)
enter2 = "4" #This is an example of what the variable looks like coming from the enterbox
enter2 = int(enter2) #enter2 now looks like 4 instead of "4"
output = enter2 - enter #this will return 1 to the variable output
if enter < '0' or enter > '999':
Python: Subtract Minute off Time Variable in Filename within Try/Except Loop
To fix this issue So, since your comment has cleared up that it'll be consistent and always newest, you can use some neat little tricks. First, the os module has a command named os.listdir(path)- this will give you the filenames of files in the given directory ("/Users/Ryan" above). Since the start is consistent and the numbers are in descending order, you can just sort the list of names using the builtin sorted(). This will sort them such that the newest one (highest ordinal name, since numbers are predictable) will be last. You can list.pop() off the last one or just access it (list[-1]) and do what you will with it (move it and such).
files_to_check = [name for name in sorted(os.listdir("/Users/...")) if name.startswith("file")]
How do I subtract the value of a item in a list and a variable python