Setting up properties from the __init__ method

user at domain.invalid user at domain.invalid
Wed Oct 29 19:22:09 EST 2003


I have gotten properties to respond correctly, but
when I try to do it in __init__:

class foo:

         def getter(self):
                 return "hello"


         def __init__(self):
                 self.prop = property(self.getter)

bar = foo()


print bar.prop
print bar.prop.fget()


I get:

<property object at 0x815a05c>
hello


So is saying self.attr in the __ini__ method different
than just saying attr=value right in the class definition?
Assigning a the return of property() behaves clearly differently
in each case.

Thanks,

Toby





More information about the Python-list mailing list