Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33089

Re: Single leading dash in member variable names?

From aahz@pythoncraft.com (Aahz)
Newsgroups comp.lang.python
Subject Re: Single leading dash in member variable names?
Date 2012-11-10 07:41 -0800
Organization The Cat & Dragon
Message-ID <k7lsiv$68d$1@panix5.panix.com> (permalink)
References <2cb240e2-7992-44eb-84cf-1aba5a411ee4@googlegroups.com> <mailman.514.1347390405.27098.python-list@python.org>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

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

csiph-web