Different values for property vs attribute???

j_mckitrick j_mckitrick at bigfoot.com
Tue May 4 15:23:21 EDT 2004


This has really got me confused:

class Klass:
 def __init__(self):
  self.mvar = 11

 def getvar(self):
  return self.mvar

 def setvar(self, v):
  self.mvar = v

 pvar = property(getvar, setvar)

k = Klass()
print 'member var is %d' % k.mvar
print 'property var is %d' % k.pvar
k.pvar = 22
print 'member var is %d' % k.mvar
print 'property var is %d' % k.pvar

----------------
This gives the output:
member var is 11
property var is 11
member var is 11
property var is 22

---------------------------

What am I missing?  Isn't the property shortcut just an accessor to
the same member variable???

jonathon



More information about the Python-list mailing list