how to use property?

Fernando Jiménez the.merck at gmail.com
Mon Sep 17 17:55:38 EDT 2012


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120917/3c463734/attachment.html>


More information about the Python-list mailing list