Make a python property with the same name as the class member name

Chris Rebert clp2 at
Fri Feb 27 17:43:15 CET 2009

On Fri, Feb 27, 2009 at 5:59 AM, Ravi <ra.ravi.rav at> wrote:
> Is it possible in python to create a property with the same name as
> the member variable name of the class. e.g.

No, because accessing the property and the instance variable are
*syntactically identical* (it's the raison detre of properties) so
there's no way for Python to know which one you mean when.
Typically, people name the variable used internally by the property as
an underscore followed by the property name (e.g. self._i).

> Class X:
>    ...
>    self.i = 10 # marker
>    ...
>    property(fget = get_i, fset = set_i)


Follow the path of the Iguana...

More information about the Python-list mailing list