Question on class member in python
bruno modulix
onurb at xiludom.gro
Mon Oct 17 05:35:29 EDT 2005
Johnny Lee wrote:
> Class A:
s/C/c/
> def __init__(self):
> self.member = 1
>
> def getMember(self):
> return self.member
>
> a = A()
>
> So, is there any difference between a.member and a.getMember?
yes : a.member is an integer, a.getMember is a bound method. You could
have found this by yourself...
Note that the getter/setter plague is useless and unpythonic. Use
properties instead if you need to control attributes access. There are
decorator idioms to make clean and easy properties, look here:
http://wiki.python.org/moin/PythonDecoratorLibrary
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list