|
我定义了个关于时间的类,在调用到一半的时候发生错误了,请大家帮我看看是什么原因,谢谢!
类代码:
class Time:
def __init__( self):
self._hour = 0
self._minute = 0
self._second = 0
def setTime( self ):
self.setHour( hour )
self.minute( minute )
self.second( second )
def setHour( self, hour ):
if 0 <= set._hour < 24 :
set._hour = hour
else:
raise ValueError , "Invalid hour value: %d " % hour
def setMinute( self, minute ):
if 0 <= set._minute < 60 :
set._minute = minute
else:
raise ValueError , "Invalid minute value: %d " % minute
def setSecond( self, second ):
if 0 <= set._second < 60 :
set._second = second
else:
raise ValueError , "Invalid second value: %d " % second
def printMilitary( self ):
print "%.2d : %.2d : %.2d" % \
( self._hour,self._minute,self._second )
def printStandard( self ):
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
调用代码我是这样写的:
from time2 import Time
time1 = Time()
print "printMilitary:" , time1.printMilitary()
print " printStandard :" , time1.printStandard()
time1.setTime( 13, 27, 6 )
print "printMilitary:" , time1.printMilitary()
print " printStandard :" , time1.printStandard()
time1.setHour( 4 )
time1.setMinute( 3 )
time1.setStandard( 34 )
print "printMilitary:" , time1.printMilitary()
print " printStandard :" , time1.printStandard()
time1是我调用的对象,我给它定义了3个属性,hour,minute和second,请帮忙看看是哪错了,谢谢.
上面是我调用类的代码
系统提示:
>>> import lei
printMilitary: 00:00:00
None
printStandard : 12:00:00 Am
None
Traceback (most recent call last):
File "<pyshell#0>", line 1, in -toplevel-
import lei
File "F:\Python24\lei.py", line 9, in -toplevel-
time1.setTime( 13, 27, 6 )
TypeError: setTime() takes exactly 1 argument (4 given)
>>>
哎......类这关真难过,不是这错就是那错,希望有经验的前辈们多指点指点我,谢谢! |
|