Property confusion

  • Thread starter kepes.krisztian
  • Start date
K

kepes.krisztian

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
 
P

Peter Otten

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,264
Latest member
FletcherDa

Latest Threads

Top