Class Time with properties : Class Definition « Class « Python

Home
Python
1.2D
2.Application
3.Buildin Function
4.Class
5.Data Structure
6.Data Type
7.Database
8.Development
9.Dictionary
10.Event
11.Exception
12.File
13.Function
14.GUI Pmw
15.GUI Tk
16.Language Basics
17.List
18.Math
19.Network
20.String
21.System
22.Thread
23.Tuple
24.Utility
25.XML
Python » Class » Class DefinitionScreenshots 
Class Time with properties
 

class Timeobject ):
   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 deleteValueself ):
      raise TypeError, "Cannot delete attribute"

   def setHourself, value ):
      if <= value < 24:
         self.__hour = value
      else:
         raise ValueError, "hour (%d) must be in range 0-23, inclusive" % value

   def getHourself ):
      return self.__hour

   hour = propertygetHour, setHour, deleteValue, "hour" )   

   def setMinuteself, value ):
      if <= value < 60:
         self.__minute = value
      else:
         raise ValueError, "minute (%d) must be in range 0-59, inclusive" % value

   def getMinuteself ):
      return self.__minute       

   minute = propertygetMinute, setMinute, deleteValue, "minute" )

   def setSecondself, value ):
      if <= value < 60:
         self.__second = value
      else:
         raise ValueError, "second (%d) must be in range 0-59, inclusive" % value

   def getSecondself ):
      return self.__second

   second = propertygetSecond, setSecond, deleteValue, "second" )

   
  
Related examples in the same category
1.Class Time with customized attribute access.
2.Simple class with slots
3.Definition and test function for class Point.
4.User-Defined Classes
5.NameTag class
6.Class instance value setting
7.Define a class
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.