What is the naming convention for accessor of a 'private' variable?
clp2 at rebertia.com
Thu Nov 19 03:47:34 CET 2009
On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
> 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.
> - _single_leading_underscore: weak "internal use" indicator. E.g. "from M
> import *" does not import objects whose name starts with an underscore.
If there's a method to access the variable, then it's not all that
private, is it?
Accessor methods are not Pythonic. Just make the attribute public by
not prefixing it with an underscore.
See also "Python is Not Java":
More information about the Python-list