class Time( object ):
def __init__( self, hourValue, minuteValue, secondValue ):
self.__hour = hourValue
self.__minute = minuteValue
self.__second = secondValue
def __str__( self ):
return "%.2d:%.2d:%.2d" % ( self.__hour, self.__minute, self.__second )
def deleteValue( self ):
raise TypeError, "Cannot delete attribute"
def setHour( self, value ):
if 0 <= value < 24:
self.__hour = value
else:
raise ValueError, "hour (%d) must be in range 0-23, inclusive" % value
def getHour( self ):
return self.__hour
hour = property( getHour, setHour, deleteValue, "hour" )
def setMinute( self, value ):
if 0 <= value < 60:
self.__minute = value
else:
raise ValueError, "minute (%d) must be in range 0-59, inclusive" % value
def getMinute( self ):
return self.__minute
minute = property( getMinute, setMinute, deleteValue, "minute" )
def setSecond( self, value ):
if 0 <= value < 60:
self.__second = value
else:
raise ValueError, "second (%d) must be in range 0-59, inclusive" % value
def getSecond( self ):
return self.__second
second = property( getSecond, setSecond, deleteValue, "second" )
|