how to use property?
Dave Angel
d at davea.name
Mon Sep 17 18:07:44 EDT 2012
On 09/17/2012 05:55 PM, Fernando Jiménez wrote:
> Hi guys!
>
> I'm noob in python and I would know how to correctly use the property. I
> have read some things about it but I do not quite understand.
>
> I found this:
>
> class C(object):
> def __init__(self):
> self._x = None
>
> @property
> def x(self):
> """I'm the 'x' property."""
> return self._x
>
> @x.setter
> def x(self, value):
> self._x = value
>
> @x.deleter
> def x(self):
> del self._x
>
> But I think it's a bad habit to use _ to change the visibility of the
> attributes as in JAVA.
>
> How to correctly use the property?
>
>
That's already correct. But if you don't like _x, then use
_rumplestiltskin.
--
DaveA
More information about the Python-list
mailing list