Simple class with slots : Class Definition : Class PYTHON examples


PYTHON examples » Class » Class Definition »

 

Simple class with slots


 

class PointWithoutSlots:
   def __init__self, xValue = 0.0, yValue = 0.0 ):
      self.x = floatxValue )
      self.y = floatyValue )

class PointWithSlotsobject ):
   __slots__ = "x""y" ]

   def __init__self, xValue = 0.0, yValue = 0.0 ):
      self.x = floatxValue )
      self.y = floatyValue )

noSlots = PointWithoutSlots()
slots = PointWithSlots()

for point in noSlots, slots ]:
   print "nProcessing an object of class", point.__class__
   
   print "point.x is:", point.x
   newValue = floatraw_input"Enter new x coordinate: " ) )
   print "set new x-coordinate value..."

   point.X = newValue

   print "The new value of point.x is:", point.x

   
  



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Class
» Class Definition