Property confusion

kepes.krisztian kepes.krisztian at peto.hu
Wed Sep 8 04:02:06 EDT 2004


Hi !

I don't understand something:

See that code:
class A(object):
      __slots__=('x','a','__v')
      def __init__(self):
          self.__v=0
      def g(self):
          print "g"
          return self.__v
      def s(self,v):
          self.__v=v
          print "s"
      GS=property(g,s)

a=A()
print a.g()
a.s(1)
print a.g()
#print a.GS
a.GS=2
print a.GS
print a.g()

It is working.
But when we remove slots, it is missing: the a.GS is not used as
property, it is access a local member. Why ?

class A(object):
      def __init__(self):
          self.__v=0
      def g(self):
          print "g"
          return self.__v
      def s(self,v):
          self.__v=v
          print "s"
      GS=property(g,s)

a=A()
print a.g()
a.s(1)
print a.g()

#print a.GS
a.GS=2
print a.GS
print a.g()


Thanx for a help:
FT








More information about the Python-list mailing list