Re: __init__() not called automatically
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: __init__() not called automatically

From: Tim Leslie <tim.leslie@gmail.com>
Date: Thu May 26 2005 - 06:46:49 CEST

On 25 May 2005 21:31:57 -0700, Sriek <scharan20@gmail.com> wrote:
> hi,
> i come from a c++ background. i ws happy to find myself on quite
> familiar grounds with Python. But, what surprised me was the fact that
> the __init__(), which is said to be the equivlent of the constructor in
> c++, is not automatically called. I'm sure there must be ample reason
> for this. I would like to know why this is so? This is my view is more
> burden on the programmer.

>>> class C:
... def __init__(self): print "Hello"
...
>>> c = C()
Hello

This looks like __init__ being called automatically to me. Are you
doing something different?

> Similarly, why do we have to explicitly use the 'self' keyword
> everytime?

http://www.python.org/doc/faq/general.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls

>
> Every kind of help would be welcome.

No worries,

Tim

>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Received on Thu Sep 29 16:14:03 2005