output

Shi Mu samrobertsmith at gmail.com
Fri Oct 14 20:48:59 EDT 2005


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?

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



More information about the Python-list mailing list