Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28896 > unrolled thread
| Started by | e.doxtator@gmail.com |
|---|---|
| First post | 2012-09-11 11:45 -0700 |
| Last post | 2012-11-10 07:41 -0800 |
| Articles | 12 — 7 participants |
Back to article view | Back to comp.lang.python
Single leading dash in member variable names? e.doxtator@gmail.com - 2012-09-11 11:45 -0700
Re: Single leading dash in member variable names? Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-11 13:06 -0600
Re: Single leading dash in member variable names? e.doxtator@gmail.com - 2012-09-11 13:53 -0700
Re: Single leading dash in member variable names? Terry Reedy <tjreedy@udel.edu> - 2012-09-11 17:34 -0400
Re: Single leading dash in member variable names? e.doxtator@gmail.com - 2012-09-11 13:53 -0700
Re: Single leading dash in member variable names? Erik Max Francis <max@alcyone.com> - 2012-09-11 15:02 -0700
Re: Single leading dash in member variable names? Tim Chase <python.list@tim.thechases.com> - 2012-09-12 05:49 -0500
Re: Single leading dash in member variable names? e.doxtator@gmail.com - 2012-09-12 08:23 -0700
Re: Single leading dash in member variable names? Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-12 10:52 -0600
Re: Single leading dash in member variable names? mdengler@gmail.com - 2012-09-12 09:53 -0700
Re: Single leading dash in member variable names? Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-12 09:23 -0600
Re: Single leading dash in member variable names? aahz@pythoncraft.com (Aahz) - 2012-11-10 07:41 -0800
| From | e.doxtator@gmail.com |
|---|---|
| Date | 2012-09-11 11:45 -0700 |
| Subject | Single leading dash in member variable names? |
| Message-ID | <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> |
All
Python noob here. Trying to understand a particular syntax:
class stuff:
def __init__(self):
self._bongo = "BongoWorld"
-----------
What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it.
[toc] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-09-11 13:06 -0600 |
| Message-ID | <mailman.514.1347390405.27098.python-list@python.org> |
| In reply to | #28896 |
On Tue, Sep 11, 2012 at 12:45 PM, <e.doxtator@gmail.com> wrote: > All > > Python noob here. Trying to understand a particular syntax: > > class stuff: > def __init__(self): > self._bongo = "BongoWorld" > > ----------- > > What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. 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.
[toc] | [prev] | [next] | [standalone]
| From | e.doxtator@gmail.com |
|---|---|
| Date | 2012-09-11 13:53 -0700 |
| Message-ID | <dcd6a7be-b42e-4f53-9c16-65a159c4e185@googlegroups.com> |
| In reply to | #28897 |
On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: > On Tue, Sep 11, 2012 at 12:45 PM, I wrote: > > > All > > > > > > Python noob here. Trying to understand a particular syntax: > > > > > > class stuff: > > > def __init__(self): > > > self._bongo = "BongoWorld" > > > > > > ----------- > > > > > > What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. > > > > 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?
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2012-09-11 17:34 -0400 |
| Message-ID | <mailman.519.1347399307.27098.python-list@python.org> |
| In reply to | #28900 |
On 9/11/2012 4:53 PM, e.doxtator@gmail.com wrote: >>> What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. >> 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. > 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. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | e.doxtator@gmail.com |
|---|---|
| Date | 2012-09-11 13:53 -0700 |
| Message-ID | <mailman.516.1347396810.27098.python-list@python.org> |
| In reply to | #28897 |
On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: > On Tue, Sep 11, 2012 at 12:45 PM, I wrote: > > > All > > > > > > Python noob here. Trying to understand a particular syntax: > > > > > > class stuff: > > > def __init__(self): > > > self._bongo = "BongoWorld" > > > > > > ----------- > > > > > > What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. > > > > 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?
[toc] | [prev] | [next] | [standalone]
| From | Erik Max Francis <max@alcyone.com> |
|---|---|
| Date | 2012-09-11 15:02 -0700 |
| Message-ID | <sY-dnYkrKKdqKdLNnZ2dnUVZ5sWdnZ2d@giganews.com> |
| In reply to | #28901 |
On 09/11/2012 01:53 PM, e.doxtator@gmail.com wrote:
> On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote:
>> On Tue, Sep 11, 2012 at 12:45 PM, I wrote:
>>> What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it.
>>
>> 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?
Where does it say that?
--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Jabber erikmaxfrancis
I will always remember / This moment
-- Sade
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2012-09-12 05:49 -0500 |
| Message-ID | <mailman.548.1347446922.27098.python-list@python.org> |
| In reply to | #28905 |
On 09/12/12 00:10, Dwight Hutto wrote: > 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
[toc] | [prev] | [next] | [standalone]
| From | e.doxtator@gmail.com |
|---|---|
| Date | 2012-09-12 08:23 -0700 |
| Message-ID | <c0a54ccd-36bb-4414-970f-67d59d8dfd6f@googlegroups.com> |
| In reply to | #28905 |
On Tuesday, September 11, 2012 5:02:31 PM UTC-5, Erik Max Francis wrote: > On 09/11/2012 01:53 PM, me wrote: > > > On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: > > >> On Tue, Sep 11, 2012 at 12:45 PM, I wrote: > > >>> What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. > > >> > > >> 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? > > > > Where does it say that? Apologies. It's in David Goodger's "Code Like A Pythonista" in the "Naming" section. (http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#naming)
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-09-12 10:52 -0600 |
| Message-ID | <mailman.571.1347468774.27098.python-list@python.org> |
| In reply to | #28975 |
On Wed, Sep 12, 2012 at 9:23 AM, <e.doxtator@gmail.com> wrote: > > On Tuesday, September 11, 2012 5:02:31 PM UTC-5, Erik Max Francis wrote: > > On 09/11/2012 01:53 PM, me wrote: > > > PEP 8 says this is bad form. What do you think? > > > > > > > > Where does it say that? > > Apologies. It's in David Goodger's "Code Like A Pythonista" in the "Naming" section. (http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#naming) That's arguing against double leading underscore, not single leading underscore. I pretty much agree with it; I rarely use the name-mangling syntax myself.
[toc] | [prev] | [next] | [standalone]
| From | mdengler@gmail.com |
|---|---|
| Date | 2012-09-12 09:53 -0700 |
| Message-ID | <159d0e9d-6fb5-41ba-a1e9-def00f5493a7@googlegroups.com> |
| In reply to | #28975 |
On Wednesday, September 12, 2012 4:23:49 PM UTC+1, (unknown) wrote: > [...] David Goodger's "Code Like A Pythonista" in the "Naming" section [says single leading underscore is bad form]. (http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#naming) Looks like it says the opposite: "[rather than trying to hide attributes with double-leading-underscores, i]t's better to use the single-leading-underscore convention, _internal".
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-09-12 09:23 -0600 |
| Message-ID | <mailman.568.1347463470.27098.python-list@python.org> |
| In reply to | #28905 |
On Tue, Sep 11, 2012 at 11:10 PM, Dwight Hutto <dwightdhutto@gmail.com> wrote: > 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.
[toc] | [prev] | [next] | [standalone]
| From | aahz@pythoncraft.com (Aahz) |
|---|---|
| Date | 2012-11-10 07:41 -0800 |
| Message-ID | <k7lsiv$68d$1@panix5.panix.com> |
| In reply to | #28897 |
In article <mailman.514.1347390405.27098.python-list@python.org>, Ian Kelly <ian.g.kelly@gmail.com> wrote: >On Tue, Sep 11, 2012 at 12:45 PM, <e.doxtator@gmail.com> wrote: >> >> Python noob here. Trying to understand a particular syntax: >> >> class stuff: >> def __init__(self): >> self._bongo = "BongoWorld" >> >> What is the significance of the leading underscore in "self._bongo"? >> I've seen this a few times and, after looking through PEP 8, I didn't >> see anything relevant, but I could have missed it. > >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 *``. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web