|
为什么我下面的程序运行总是报错呀,
newman0708@newman0708-desktop:~/doc/python$ ./fig07_02.py
from: can't read /var/mail/myClock
./fig07_02.py: line 6: syntax error near unexpected token `('
./fig07_02.py: line 6: `time1=Time() #create object of class Time'
应该 怎么改呀,请各位指点一下,谢谢
#Fig.7.1: myClock.py
#Simple definition of class Time.
class Time:
"""Time abstract data type (ADT) definition"""
def __init__(self):
"""initialize hour,minute and second to zero"""
self.hour=0
self.minute=0
self.second=0
def printMilitary(self):
"""rints object of class Time in military format """
print"%.2d:%.2d:%.2d" % \
(self.hour,self.minite,self.second),
def printStandard(self):
"""rints object of class Time in standard format"""
standardTime=""
if self.hour==0 or self.hour==12:
standardTime+="12:"
else:
standardTime+="%d:" %(self.hour % 12)
standardTime+="%.2d:%.2d" % (self.minute,self.second)
if self.hour<12:
standardTime+=" AM"
else:
standardTime+=" PM"
print standardTime,
#Fig. 7.2 : fig07_02.py
#Creating and manpulating object of class Time.
from myClock import Time #import class definition from file
time1=Time() #create object of class Time
#access object's attributes
print "Time attributes of time1 are:"
print "time1.hour:", time1.hour
print "time1.minute:", time1.minute
print "time1.second:", time1.second
#access object's metnoas
print "\n Calling method printMilitary:",
time1.printMilitary()
print "\n Calling method printStandard:",
time1.printStandard()
#change value of object's attributes
print "\n\nChanging time1's hour attribute..."
time1.hour=25
print "Calling method printMilitary after alteration:",
time1.printMilitary() |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|