Can you set a class instance's attributes to zero by setting the instance to zero?

Gerard Flanagan grflanagan at yahoo.co.uk
Sat Nov 19 08:29:07 EST 2005


Hello

If I have the Vector class below, is there a means by which I can have
the following behaviour


>>>A = Vector(1, 2)
>>>print A
(1, 2)
>>>A = 0
>>>print A
(0, 0)

If there is such a means, will it still work with the __slots__
attribution uncommented?

Thanks

class Vector(object):

    #__slots__ = ('x', 'y')

    def __init__(self, a=0, b=0 ):
            self.x = a
            self.y = b

    def __repr__(self):
        return '(%s, %s)' % (self.x, self.y)




More information about the Python-list mailing list