Property confusion

kepes.krisztian kepes.krisztian at peto.hu
Wed Sep 8 05:18:02 EDT 2004


Peter wrote:
>>>>>

    kepes.krisztian wrote:

    [Same old question under a new subject]

    If you don't receive an answer within a reasonable time span you should
    consider rephrasing the problem, not just the header.

    I tried the code you gave and could not perceive any difference in the
    output of the two snippets. Maybe you can post an interactive
    session with
    just the statements that produce different output? Or you rename one
    class,
    to B, say, and add an assertion you expect to succeed but which
    fails, e.
    g.:

    class A(object):
    #...
    class B(object):
    #...

    assert A().some_attr == B().some_attr


    Peter


>>>>>
Sorry, I wrote wrong code. The good is that:


class A:
      __slots__=('x','a','__v')
      def __init__(self):
          self.__v=0
      def g(self):
          return self.__v
      def s(self,v):
          self.__v=v
      GS=property(g,s)

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

lists=[[],[]]

key=0
lists[key].append("A")
a=A()
lists[key].append(a.g())
a.s(1)
lists[key].append(a.g())
lists[key].append(a.GS)
a.GS=2
lists[key].append(a.GS)
lists[key].append(a.g())

key=1
lists[key].append("B")
b=B()
lists[key].append(b.g())
b.s(1)
lists[key].append(b.g())
lists[key].append(b.GS)
b.GS=2
lists[key].append(b.GS)
lists[key].append(b.g())

print lists[0]
print lists[1]

If I not use object, the GS is used as member, not property.

['A', 0, 1, 1, 2, 1]
['B', 0, 1, 1, 2, 2]






More information about the Python-list mailing list