What is the naming convention for accessor of a 'private' variable?

Ben Finney ben+python at benfinney.id.au
Wed Nov 18 22:01:45 EST 2009


Peng Yu <pengyu.ut at gmail.com> writes:

> The above webpage states the following naming convention. Such a
> variable can be an internal variable in a class. I'm wondering what is
> the naming convention for the method that access such variable.

A property <URL:http://docs.python.org/library/functions.html#property>
named with a regular public attribute name::

    class Foo(object):

        def __init__(self, spam):
            self._spam = spam

        @property
        def spam(self):
            return self._spam

-- 
 \          “The only tyrant I accept in this world is the still voice |
  `\                                          within.” —Mahatma Gandhi |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list