Overriding properties
Nick Patavalis
npat at efault.net
Sat Dec 11 20:06:00 EST 2004
More information about the Python-list mailing list
Sat Dec 11 20:06:00 EST 2004
- Previous message (by thread): Overriding properties
- Next message (by thread): Hashes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Why does the following print "0 0" instead of "0 1"? What is the
canonical way to rewrite it in order to get what I obviously expect?
class C(object):
__val = 0
def set_value(self, val):
if val < 0 : self.__val = 0
else : self.__val = val
def get_value(self):
return self.__val
value = property(get_value, set_value)
class CC(C):
def set_value(self, val):
if val < 0: self.__val = 1
else : self.__val = val
c = C()
cc = CC()
c.value = -1
cc.value = -1
print c.value, cc.value
Thanks in advance
/npat
- Previous message (by thread): Overriding properties
- Next message (by thread): Hashes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list