python的 slots使用,pythonslots使用,class PointW
文章由Byrx.net分享于2019-03-23 07:03:53
python的 slots使用,pythonslots使用,class PointW
class PointWithoutSlots: def __init__( self, xValue = 0.0, yValue = 0.0 ): self.x = float( xValue ) self.y = float( yValue )class PointWithSlots( object ): __slots__ = [ 'x', 'y' ] def __init__( self, xValue = 0.0, yValue = 0.0 ): self.x = float( xValue ) self.y = float( yValue )noSlots = PointWithoutSlots()slots = PointWithSlots()for point in [ noSlots, slots ]: print '\nProcessing an object of class', point.__class__ print 'point.x is:', point.x newValue = float( raw_input( 'Enter new x coordinate: ' ) ) print 'set new x-coordinate value...' point.X = newValue print 'The new value of point.x is:', point.x
评论关闭