[Tutor] AttributeError in class Today
Thomas Rivas
trivas7@rawbw.com
Fri, 31 May 2002 15:01:14 -0700
Hi all -- Newbie question here:
When I rum Listing 10.7 from 'Teach Yourself Python in 24 Hours:'
#!/usr/local/bin/python
import time
import now
class today(now.now):
def __init__(self, y = 1970):
now.now.__init__(self)
def update(self,tt):
if len(tt) < 9:
raise TypeError
if tt[0] < 1970 or tt[0] > 2038:
raise OverflowError
self.t = time.mktime(tt)
self(self.t)
if __name__ == "__main__":
n = today()
print "The year is", n.year
print n
x = today()
s = `x`
print s
tt = (1999, 7, 16, 12, 59, 59, 0, 0, -1)
x.update(tt)
print x
I get the following result with an AttributeError:
The year is 2002
<__main__.today instance at 0x83f891c>
<__main__.today instance at 0x83f891c>
Traceback (most recent call last):
File".../py_snips/today, line 22 in ?
x.update(tt)
File".../py_snips/today, line 13, in update
self(self.t)
AttributeError: today instance has no __call__ method
My question is: What arguments should this __call__ method have?; where
should I put it the update() function? Is the problem with the 'now' module
that was created and imported? In short, what's happening here?
Thank for the help.