[Tutor] output question
Shi Mu
samrobertsmith at gmail.com
Sat Oct 15 03:10:42 CEST 2005
I found the code for class "now". I got confused by two things:
First, how did the former code I posted know to import tis module of "Now";
Second. what does "\" mean following "self.year,"
Thanks a lot!
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)
def __repr__(self):
return time.ctime(self.t)
def __call__(self,t=-1.0):
if t < 0.0:
self.t = time.time()
else:
self.t = t
self.storetime()
On 10/14/05, Kent Johnson <kent37 at tds.net> wrote:
> Shi Mu wrote:
> > After I run the following python code, I expect to have the printing such as:
> > The year is 2005
> >
> > However, I got something like:
> > The year is 2005
> > Fri Oct 14 17:43:31 2005
> > Fri Oct 14 17:43:31 2005
> > The year is 2005
> >
> > What is the reason?
>
> Maybe coming from module 'now'? What is that?
>
> Kent
>
> >
> > The code follows:
> >
> > 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
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list