Re: how to use property?

Discussion in 'Python' started by Dave Angel, Sep 17, 2012.

  1. Dave Angel

    Dave Angel Guest

    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
     
    Dave Angel, Sep 17, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Newton
    Replies:
    3
    Views:
    9,480
    Brock Allen
    Apr 4, 2005
  2. Joshua Beall
    Replies:
    1
    Views:
    450
    Bertilo Wennergren
    Dec 10, 2003
  3. Noozer
    Replies:
    10
    Views:
    2,155
    Mitja
    Oct 13, 2004
  4. Nathan Sokalski
    Replies:
    1
    Views:
    1,120
    =?Utf-8?B?SmVk?=
    Apr 29, 2006
  5. Sky
    Replies:
    2
    Views:
    295
    Robert Koritnik
    Oct 1, 2004
Loading...

Share This Page