I tried reading through some of the other questions but I still can't get it to work.
Basically I'm using a quick and dirty function called time_string() to return the date and time in a string formatted the way I want. If I run time_string directly, it works fine. If I call it from another function I get an AttributeError.
time_string
import time
def time_string(): #Never mind the unreadable formatting
return str(time.localtime().tm_hour)+':'+str(time.localtime().tm_min)+':'+str(time.localtime().tm_sec)+\
' '+str(time.localtime().tm_year)+'/'+str(time.localtime().tm_mon)+'/'+str(time.localtime().tm_mday)
if __name__ == '__main__':
print time_string()
Running time_string directly
13:46:13 2012/7/19
Other function
from misc.time_string import time_string
def main():
print time_string()
if __name__ == '__main__':
main()
Running other function
Traceback (most recent call last): File "#Filepath#", line 10, in main() File "#Filepath#", line 7, in main print time_string() File "#Filepath#", line 9, in time_string ' '+str(time.localtime().tm_year)+'/'+str(time.localtime().tm_mon)+'/'+str(time.localtime().tm_mday) AttributeError: 'module' object has no attribute 'localtime'
I'm assuming its some issue with time not getting imported or something but it's boggling my mind
Thanks for the help!
time.pyb/c i think it's shadowing the stdlib time module.strftime?time_string.pyand afterimport timeput this line:print repr(test)and tell us what you see, if you are really importing the stdlib time you should get:<module 'time' (built-in)>if not you will get something lile:<module 'time' from '<some_path>'>