I am using Python 2.7 for Windows, and I am writing a script that uses both time modules and date-time modules. I have done this before, but python seems very moved by the fact that both modules are loaded, and the methods that I used before do not work. Here is my syntax that I used and the errors that I am currently getting.
First I tried:
from datetime import * from time import * ... checktime = datetime.today() - timedelta(days=int(2)) checktime = checktime.timetuple() ... filetimesecs = os.path.getmtime(webgatelogdir + '/' + fn) file = webgatelogdir + '/' + fn filetime = localtime(filetimesecs) ... else: time.sleep(60)
ERROR:
else: time.sleep(60) AttributeError: 'builtin_function_or_method' object has no attribute 'sleep'
Then I tried:
from datetime import * from time import * ... checktime = datetime.today() - timedelta(days=int(2)) checktime = checktime.timetuple() ... filetimesecs = os.path.getmtime(webgatelogdir + '/' + fn) file = webgatelogdir + '/' + fn filetime = localtime(filetimesecs) ...
and I had no mistakes, but there was no delay in sleep.
Next I tried:
from datetime import * import time ... checktime = datetime.today() - timedelta(days=int(2)) checktime = checktime.timetuple() ... filetimesecs = os.path.getmtime(webgatelogdir + '/' + fn) file = webgatelogdir + '/' + fn filetime = localtime(filetimesecs) ...
ERROR:
filetime = localtime(filetimesecs) NameError: name 'localtime' is not defined
Another modification, and I tried this:
import time import datetime ... checktime = datetime.today() - timedelta(days=int(2)) checktime = checktime.timetuple() ... filetimesecs = os.path.getmtime(webgatelogdir + '/' + fn) file = webgatelogdir + '/' + fn filetime = localtime(filetimesecs) ... #else: time.sleep(60) # comment out time.sleep statement
ERROR
checktime = datetime.today() - timedelta(days=int(2)) AttributeError: 'module' object has no attribute 'today'
Finally, I tried this:
import time from datetime import * ... checktime = datetime.today() - timedelta(days=int(2)) checktime = checktime.timetuple() ... filetimesecs = os.path.getmtime(webgatelogdir + '/' + fn) file = webgatelogdir + '/' + fn filetime = localtime(filetimesecs) ...
ERROR:
checktime = datetime.today() - timedelta(days=int(2)) AttributeError: 'module' object has no attribute 'today'
So, I'm not sure how to make two modules play well. Or I need another method to delay in a script.
Suggestions? Or pointers to the mistakes I made?
Thanks.