Re: python: what's with the underscores?

  • From: Tyler Littlefield <tyler@xxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sun, 27 Dec 2009 15:56:15 -0700

the __init__(self) is basically the constructer. it gets called when you create 
a new object of that type. I believe there's a destructer-type, as well.
On Dec 27, 2009, at 3:46 PM, R Dinger wrote:

> Python does not have constructors like C++.  It does have a function named 
> __init__, which serves as an initializer function for initializing objects. 
> But there can only be one of them.
> 
> Self is similar to "this" in C++, but is always explicitly stated and, of 
> course, like C++ refers to the underlying object instance.
> 
> Richard
> ----- Original Message ----- From: "Alex Hall" <mehgcap@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Sunday, December 27, 2009 2:13 PM
> 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

Other related posts: