Re: [Tutor] FW: Module 1 question

Magnus Lycka magnus at thinkware.se
Thu Jun 17 12:30:09 EDT 2004


christopher lavezza wrote:
> Can anyone help us out with this problem in our script?

Just as the error message says, the module (time) has no attribute called
strtime. I suspect you misspelled strftime. Note the 'f' in the name. The
names comes from the C language library module "time". The Python time
module is just a thin wrapper for the standard C library.

>>> import time
>>> time.strtime

Traceback (most recent call last):
  File "<pyshell#17>", line 1, in -toplevel-
    time.strtime
AttributeError: 'module' object has no attribute 'strtime'
>>> time.strftime
<built-in function strftime>
>>> t=time.strftime('%a, %d %b %Y %H:%M:%S' , time.localtime(time.time()))
>>> print t
Thu, 17 Jun 2004 18:06:22

For a more "modern" and high level approach to date and time handling, 
Python has a nice module called datetime since version 2.3. Using datetime, 
it's more easy to do time calculations etc. You don't need to bother about
tuples and numeric representations. You simply use a datetime object. The 
datetime module is also safe from year 1 to 9999, while the time module is 
limited to 1970 to 2038 on 32 bit systems, just as the underlying C library.

>>> import datetime
>>> print datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S')
Thu, 17 Jun 2004 18:13:44

Read the Python Library Reference for more info:
http://docs.python.org/lib/module-time.html and
http://docs.python.org/lib/module-datetime.html

> >Traceback (most recent call last):
> >   File "Script5_1.py", line 23, in ?
> >     a.deposit(550.23)
> >   File "Script5_1.py", line 8, in deposit
> >     t=time.strtime('%a, %d %b %Y %H:%M:%S' , time.localtime(time.time()
> >+ 0))
> >AttributeError: 'module' object has no attribute 'strtime'


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus at thinkware.se



More information about the Tutor mailing list