Shi Mu wrote: > 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";
You told it to with the statement import now This statement tells Python to look in the directories in its path for a file called now.py and load it, assigning the resulting module object to the name 'now'. > Second. what does "\" mean following "self.year," It is a line continuation character - it means the text of the line continues on the next line. Is there anything else in now.py? Any print statements? When I run the code you have posted so far I just get one line of output. Kent > 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 <[EMAIL PROTECTED]> 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@python.org >>>http://mail.python.org/mailman/listinfo/tutor >>> >>> >> >>_______________________________________________ >>Tutor maillist - Tutor@python.org >>http://mail.python.org/mailman/listinfo/tutor >> > > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor