Repeating actions on a timer
You can repeat an action every five seconds by combining an infinite loop with the time.sleep()
function, like so:
import time
while True:
time.sleep(5) # wait five seconds
print (time.time()) # print the time
Remember to have some kind of break
condition in here if you need it, otherwise the loop will run forever.
"TypeError: coercing to Unicode: need string or buffer, list found"
Your problem is in the line
Time = time.ctime(os.path.getmtime(contents))
You have provided a list of filenames. The os.path.getmtime
function expects one filename at a time. The error message is telling you that it has no idea how to convert a list of filenames into a filename.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…