Single leading dash in member variable names?

E

e.doxtator

All

Python noob here. Trying to understand a particular syntax:

class stuff:
def __init__(self):
self._bongo = "BongoWorld"
 
I

Ian Kelly

All

Python noob here. Trying to understand a particular syntax:

class stuff:
def __init__(self):
self._bongo = "BongoWorld"

Single leading underscore is a convention indicating that the name
should be considered private and not used externally. It's a softer
version of the double leading underscore that means basically the same
thing but has syntactic significance.
 
E

e.doxtator

Single leading underscore is a convention indicating that the name

should be considered private and not used externally. It's a softer

version of the double leading underscore that means basically the same

thing but has syntactic significance.

Thank you!

PEP 8 says this is bad form. What do you think?
 
E

e.doxtator

Single leading underscore is a convention indicating that the name

should be considered private and not used externally. It's a softer

version of the double leading underscore that means basically the same

thing but has syntactic significance.

Thank you!

PEP 8 says this is bad form. What do you think?
 
T

Terry Reedy

PEP 8 says this is bad form. What do you think?

Please quote the specific statement you want commented. The stdlib
routinely uses _names for internal implementation objects. __ugh is
perhaps never used.
 
T

Tim Chase

Not to jump in with another question(this seems somewhat relevant
to the conversation, maybe not), but is this similar to a
private,public, or protected class similar to the C type langs?

Close, but C-like languages tend to strictly enforce it, while in
Python it's more of a gentleman's agreement. Python doesn't *stop*
you from mucking with them, but you've been advised that, if it
breaks, you get to keep both parts.

-tkc
 
I

Ian Kelly

Not to jump in with another question(this seems somewhat relevant to the
conversation, maybe not), but is this similar to a private,public, or
protected class similar to the C type langs?

More like "this is an implementation detail and in the future it could
be changed or removed entirely without warning". I consider them
private unless documented otherwise.
 
A

Aahz

Single leading underscore is a convention indicating that the name
should be considered private and not used externally. It's a softer
version of the double leading underscore that means basically the same
thing but has syntactic significance.

Note that the convention is rooted in an actual semantic meaning for
single underscore:

``from foo import *`` ignores any module global names in foo that start
with a single leading underscore. Obviously, this has little effect for
most Python programs because you DON'T USE ``import *``.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top