Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29389

Re: how to use property?

Date 2012-09-17 18:07 -0400
From Dave Angel <d@davea.name>
Subject Re: how to use property?
References <CAGYVzb1-D4xyCeYHL6R1_O8msDfn9pd=UcuYhno5i3HCkB_t=A@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.841.1347919692.27098.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: how to use property? Dave Angel <d@davea.name> - 2012-09-17 18:07 -0400

csiph-web