Help with code

Steve Holden sholden at holdenweb.com
Wed Feb 20 08:41:31 EST 2002


"Dmitry Savchuk" <compedu at nh.km.ua> wrote in message
news:a4votp$mmf$1 at infocom.km.ua...
> Hi,
>
> I'd like to ask you a question. There is a code from the book of Ivan Van
> Laningham "Sams Teach Yourself Python in 24 Hours (Teach Yourself -- 24
> Hours)":
>
> import time
> class now:
>     def _init_(self):
>         self.t=time.time()
>         self.storetime()
>     def storetime(self):
>         self.year,\
>         self.month,\
>         self.day,\
>         self.hour,\
>         self.minute,\
>         self,second,\
>         self.dow,\
>         self.doy,\
>         self,dst=time.localtime(self.t)
>     def _str_(self):
>         return time.ctime(self.t)
>
> n=now()
> print "The year is ", n.year
> print n
> s=`n`
> print s
>
>
> It doesn't work properly. Appear a messge:
>
> The year is
> Traceback (most recent call last):
>   File "C:\Projects\test", line 20, in ?
>     print "The year is ", n.year
> AttributeError: now instance has no attribute 'year'
>
> Where is my mistake?
>
Besides the underscores another poster mentioned, note also that you have
replaced a period with a comma. Your line which reads

            self,dst=time.localtime(self.t)

should read

            self.dst=time.localtime(self.t)


--
Consulting, training, speaking: http://www.holdenweb.com/
Author, Python Web Programming: http://pydish.holdenweb.com/pwp/

"This is Python.  We don't care much about theory, except where it
intersects with useful practice."  Aahz Maruch on c.l.py







More information about the Python-list mailing list