RE: python: what's with the underscores?

  • From: "edward" <personal.edward@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 27 Dec 2009 17:53:09 -0500

Hello 
Two underscores before and after the method name means it's a built in class
and you are calling a method within that class.  Two underscores before an
attribute and only two before, none after, means it's a private attribute.  

Example:
__self.atribute=attribute means it's a private attribute.
Def __init__(self,): means its built in.

Edward
 

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex Hall
Sent: Sunday, December 27, 2009 5:34 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: python: what's with the underscores?

So the double underscore means both a constructor and built-in method? Can I
not have a private non-built-in method, or a public built-in method?


Have a great day,
Alex
New email address: mehgcap@xxxxxxxxx
----- Original Message ----- 
From: "edward" <personal.edward@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Sunday, December 27, 2009 17:31
Subject: RE: python: what's with the underscores?


> Hello
> 1. python definitely has constructor methods.  Syntax is
> def__init__(self,paramitors separated by commas):
> In the init constructor method you need to of course define your 
> attributes.
> Syntax is self.name of attributes=name of parameter.
>
> 2. I am not sure why you need self. Its used but I think most don't know
> why.  It may be only used in methods in a class, and or when you are
> referencing a attribute or method in the same class.  Maybe someone else 
> can
> elaborate on this because I would also like to know.  I use self but it
> doesn't really get in the way and it doesn't point to a parameter as far 
> as
> I know.
> 3. two underscores before an attribute make the attribute private. Syntax
> __self.atribute=attribute. Likewise, two underscores before and after a
> method name signify a built in python method such as __init and __str__.
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex Hall
> Sent: Sunday, December 27, 2009 5:14 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Re: python: what's with the underscores?
>
> Okay, but (A) I did not think Python had constructor methods and (B) why 
> do
> I always see methodName(self): like in your example?
>
>
> Have a great day,
> Alex
> New email address: mehgcap@xxxxxxxxx
> ----- Original Message ----- 
> From: "edward" <personal.edward@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Sunday, December 27, 2009 17:11
> Subject: RE: python: what's with the underscores?
>
>
>> Two underscores signify either a constructor method or a built in method 
>> I
>> think.  Like the str method.  If you want to define string formatting 
>> with
>> your class its defined by two underscores before and after the method
>> name.
>> example __str__(self):
>>
>>
>> -----Original Message-----
>> From: programmingblind-bounce@xxxxxxxxxxxxx
>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Alex Hall
>> Sent: Sunday, December 27, 2009 3:58 PM
>> To: Blind Programming List
>> Subject: python: what's with the underscores?
>>
>> In python, why are some method names surrounded by two underscores? Even
>> some filenames have these two underscores, though I imagine that is more
>> of
>> a convention than anything else. What do the underscores mean, if
>> anything?
>>
>>
>> Have a great day,
>> Alex
>> New email address: mehgcap@xxxxxxxxx
>>
>> __________
>> View the list's information and change your settings at
>> //www.freelists.org/list/programmingblind
>>
>> __________
>> View the list's information and change your settings at
>> //www.freelists.org/list/programmingblind
>>
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
> 

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: