A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/327408.html below:

What's the difference between VAR and _VAR_?

What's the difference between VAR and _VAR_?Michael Ekstrand mekstran at scl.ameslab.gov
Sat Sep 10 11:48:08 EDT 2005
On 8 Sep 2005 22:48:05 -0700
"Johnny Lee" <johnnyandfiona at hotmail.com> wrote:
> I thought there must be something special when you named a VAR with
> '_' the first character. Maybe it's just a programming style and I had
> thought too much...

It is just a programming style issue. In Python, variables and functions
beginning with '_' are regarded by convention to be semi-private;
essentially the Python equivalent of 'protected'. Since Python has no
formal access specifications, conventions like this have been adopted.
Likewise, '__' is private. Code using your code can bypass this, of
course, but it's just a signal to the programmer 'avoid using this; it
is an internal detail that may change.'

Incidentally, epydoc regards all items beginning with '_' as private,
and hides them from the public documentation it generates.

And, in one project I'm working on, I use underscores to
base/background/helper modules in a mechanism where modules are
dynamically loaded (to prevent name collisions, since no dynamically
loaded module will begin with an underscore).

- Michael

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4