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


Groups > comp.lang.python > #28763 > unrolled thread

Beginner Q: What does the double underscore __ mean?

Started byStarPilgrim <aaronpil@gmail.com>
First post2012-09-09 04:03 -0700
Last post2012-09-09 22:38 -0700
Articles 7 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  Beginner Q: What does the double underscore __ mean? StarPilgrim <aaronpil@gmail.com> - 2012-09-09 04:03 -0700
    Re: Beginner Q: What does the double underscore __ mean? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-09 12:23 +0100
    Re: Beginner Q: What does the double underscore __ mean? Dave Angel <davea@dejaviewphoto.com> - 2012-09-09 08:39 -0400
      Re: Beginner Q: What does the double underscore __ mean? hamilton <hamilton@nothere.com> - 2012-09-09 10:04 -0600
        Re: Beginner Q: What does the double underscore __ mean? Dave Angel <d@davea.name> - 2012-09-09 16:54 -0400
        Re: Beginner Q: What does the double underscore __ mean? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-09 22:05 +0000
    Re: Beginner Q: What does the double underscore __ mean? Bryan <bryanjugglercryptographer@yahoo.com> - 2012-09-09 22:38 -0700

#28763 — Beginner Q: What does the double underscore __ mean?

FromStarPilgrim <aaronpil@gmail.com>
Date2012-09-09 04:03 -0700
SubjectBeginner Q: What does the double underscore __ mean?
Message-ID<3dcd70d0-17b5-40a4-803a-eed66639b6e7@googlegroups.com>
Hi all,
Brand new to python. I was wondering what the __ underscore means?
For example, there is a line of code:

__name__=='__main__'


and I don't know what the double underscore is used for.

[toc] | [next] | [standalone]


#28765

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2012-09-09 12:23 +0100
Message-ID<mailman.415.1347189902.27098.python-list@python.org>
In reply to#28763
On 09/09/2012 12:03, StarPilgrim wrote:
> Hi all,
> Brand new to python. I was wondering what the __ underscore means?
> For example, there is a line of code:
>
> __name__=='__main__'
>
>
> and I don't know what the double underscore is used for.
>

Start here http://docs.python.org/reference/datamodel.html#specialnames

-- 
Cheers.

Mark Lawrence.

[toc] | [prev] | [next] | [standalone]


#28767

FromDave Angel <davea@dejaviewphoto.com>
Date2012-09-09 08:39 -0400
Message-ID<mailman.416.1347194363.27098.python-list@python.org>
In reply to#28763
See the identical thread you posted on tutor, where it was a better match.
 


-- 

DaveA

[toc] | [prev] | [next] | [standalone]


#28785

Fromhamilton <hamilton@nothere.com>
Date2012-09-09 10:04 -0600
Message-ID<k2iem2$jes$1@dont-email.me>
In reply to#28767
On 9/9/2012 6:39 AM, Dave Angel wrote:
> See the identical thread you posted on tutor, where it was a better match.
>
>
>
Would you please post that link for those of us that did not see that one.

Thanks

[toc] | [prev] | [next] | [standalone]


#28796

FromDave Angel <d@davea.name>
Date2012-09-09 16:54 -0400
Message-ID<mailman.428.1347224127.27098.python-list@python.org>
In reply to#28785
On 09/09/2012 12:04 PM, hamilton wrote:
> On 9/9/2012 6:39 AM, Dave Angel wrote:
>> See the identical thread you posted on tutor, where it was a better
>> match.
>>
>>
>>
> Would you please post that link for those of us that did not see that
> one.
>
> Thanks
>
it's a mailing list.  There's no links to the mail in my folder. 

Googling shows me:

http://code.activestate.com/lists/python-tutor/90564/



-- 

DaveA

[toc] | [prev] | [next] | [standalone]


#28797

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-09-09 22:05 +0000
Message-ID<504d12c4$0$29890$c3e8da3$5496439d@news.astraweb.com>
In reply to#28785
On Sun, 09 Sep 2012 10:04:18 -0600, hamilton wrote:

> On 9/9/2012 6:39 AM, Dave Angel wrote:
>> See the identical thread you posted on tutor, where it was a better
>> match.
>>
>>
>>
> Would you please post that link for those of us that did not see that
> one.

http://mail.python.org/pipermail/tutor/2012-September/091388.html

You can see the tutor archives, or subscribe to the list, from here:

http://mail.python.org/mailman/listinfo/tutor


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#28801

FromBryan <bryanjugglercryptographer@yahoo.com>
Date2012-09-09 22:38 -0700
Message-ID<0cd34f31-6b7d-4ff2-b9dd-e711b1f88963@j2g2000pbg.googlegroups.com>
In reply to#28763
StarPilgrim wrote:
> Brand new to python. I was wondering what the __ underscore means?
> For example, there is a line of code:
>
> __name__=='__main__'
>
> and I don't know what the double underscore is used for.

Ah, tricky. That's not just double underscore; it's double ended
double underscore. Double ended double underscore means that it
invokes special behavior in the Python language. It means fair
warning. Look this up.

Never name your own variables with double ended double underscore. The
one exception is if you are proposing a change to the Python language
and seeking the blessing of our BDFL. Such names are reserved for the
Python language.

Leading double underscore without trailing double underscore means
that the programmer knows and loves some other object-oriented
language, and this other language has a notion of trying to enforce
that this member variable is "private", and Python is meeting him half
way. The programmer of the class advises you not to manipulate this
member variable directly and Python has bowed to convention and done
some name mangling. It's often useful, usually naive, fundamentally
insecure, and tangential to the zen Python.

A lesser known Python convention is the double ended single
underscore. Whether it even rates as convention might be arguable, but
it's there in the critical _fields_ member of the Structure and Union
base classes in the standard ctypes module. It means special within
the particular class. To the Python language it's just another name,
but the authors of the class have coded it to look up that name and do
something interesting with the associated value.

-Bryan

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web