__init__() not called automatically

2005-05-25 Thread Sriek
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

Re: __init__() not called automatically

2005-05-25 Thread Tim Leslie
On 25 May 2005 21:31:57 -0700, Sriek <[EMAIL PROTECTED]> 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 a

Re: __init__() not called automatically

2005-05-25 Thread Paul McNett
Sriek 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. What do you mean by automati

Re: __init__() not called automatically

2005-05-25 Thread Sriek
Tim pointed out rightly that i missed out the most crucial part of my question. i should have said that __init__() is not called automatically only for the inheritance hierarchy. we must explicitly call all the base class __init__() fuctions explicitly. i wanted a reason for that. Thanks Tim. --

Re: __init__() not called automatically

2005-05-25 Thread Steven Bethard
Paul McNett wrote: > Sriek wrote: >> 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. > [snip]

Re: __init__() not called automatically

2005-05-25 Thread Sakesun Roykiattisak
Does c++ call base class constructor automatically ?? If I'm not wrong, in c++ you also have to call base class constructor explicitly. Python just do not enforce the rule. You can leave it as desire. BTW, I've once been an C++ expert. Knowing python kill that skill. However, I'm not regret. I

Re: __init__() not called automatically

2005-05-26 Thread Sriek
if i understand C++ right, in c++ you CAN explicitly call the base constructor ( for eg. if it requires some particular arguements ), but, the compiler automatically has to call the base class constructor ( see the rules for constructing an object of the derived classes ). But, yes, C++ can be too

Re: __init__() not called automatically

2005-05-26 Thread Sriek
maybe like this: we can have the default behaviour as calling the default constructor ( with default arguements where required ). Along with this, keep the option open to call constructors explicitly. My only contention is that there may be a greater reason for this rule in the Python Language. t

Re: __init__() not called automatically

2005-05-26 Thread Jeremy Sanders
On Wed, 25 May 2005 21:31:57 -0700, Sriek wrote: > Similarly, why do we have to explicitly use the 'self' keyword everytime? I didn't like that when starting Python. Now when I look back at C++ code, I find it very hard to work out which variables and methods and members, and which are not, unles

Re: __init__() not called automatically

2005-05-26 Thread John Roth
"Sriek" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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

Re: __init__() not called automatically

2005-05-26 Thread Dan Sommers
On 25 May 2005 21:31:57 -0700, "Sriek" <[EMAIL PROTECTED]> wrote: > Similarly, why do we have to explicitly use the 'self' keyword > everytime? Why do they (the C++ programmers) prepend "m_" to otherwise perfectly good member names? Regards, Dan -- Dan Sommers

Re: __init__() not called automatically

2005-05-26 Thread Andrew Koenig
"Sakesun Roykiattisak" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Does c++ call base class constructor automatically ?? > If I'm not wrong, in c++ you also have to call base class constructor > explicitly. In C++, if you don't call a base-class constructor (I am saying "a" ra

Re: __init__() not called automatically

2005-05-26 Thread Steven Bethard
Sriek wrote: > maybe like this: > we can have the default behaviour as calling the default constructor > ( with default arguements where required ). Along with this, keep the > option open to call constructors explicitly. Ok, so here's another example: def init(self): print "An __init__ met

Re: __init__() not called automatically

2005-05-26 Thread Sri Charan
The compiler also calls the default arguement constructor automatically, if such a constructor is provided for the base class(es); but, this becomes a special case of what has been said by Andrew Koenig. So, it is NOT just the no arguement constructor that is automatically called; note that the de

Re: __init__() not called automatically

2005-05-26 Thread Sri Charan
I guess you are right. -- http://mail.python.org/mailman/listinfo/python-list

Re: __init__() not called automatically

2005-05-26 Thread bruno modulix
Paul McNett wrote: > Sriek wrote: > (snip) >> Similarly, why do we have to explicitly use the 'self' keyword >> everytime? > > > This is closer to a wart, IMO, I've always explicitelly used the (implied) 'this' pseudo-pointer in Java, C++ etc. The wart is in all those languages that don't make

Re: __init__() not called automatically

2005-05-26 Thread Roy Smith
bruno modulix <[EMAIL PROTECTED]> wrote: > I've always explicitelly used the (implied) 'this' pseudo-pointer in > Java, C++ etc. The wart is in all those languages that don't makes it > mandatory IMHO !-) And the correlary wart in Python is that the first argument to a method is not required to b

Re: __init__() not called automatically

2005-05-26 Thread John Abel
bruno modulix wrote: >Paul McNett wrote: > > >>Sriek wrote: >> >> >> >(snip) > > >>>Similarly, why do we have to explicitly use the 'self' keyword >>>everytime? >>>This is closer to a wart, IMO, >>> >>> > > > Here's one of the shorter threads discussing 'self'. I remember one lo

Re: __init__() not called automatically

2005-05-26 Thread Bruno Desthuilliers
Roy Smith a écrit : > bruno modulix <[EMAIL PROTECTED]> wrote: > >>I've always explicitelly used the (implied) 'this' pseudo-pointer in >>Java, C++ etc. The wart is in all those languages that don't makes it >>mandatory IMHO !-) > > > And the correlary wart in Python is that the first argument

Re: __init__() not called automatically

2005-05-26 Thread Sakesun Roykiattisak
Wow.. Andrew Koenig.. I found your name in many c++ books I read. Never know you are hanging around in python python mailing-list. (or perhaps python newsgroup, whatever it is) Thanks for the explanation. Andrew Koenig wrote: >"Sakesun Roykiattisak" <[EMAIL PROTECTED]> wrote in message >news:

Re: __init__() not called automatically

2005-05-26 Thread Michele Simionato
If you really want, you can customize the object system to automatically call __init__, via a custom metaclass. There is an example in my ACCU lectures (cooperative_init.py): http://www.reportlab.org/~andy/accu2005/pyuk2005_simionato_wondersofpython.zip Michele Simionato -- http://mail.python.o

Re: __init__() not called automatically

2005-05-27 Thread Simon Brunning
On 26 May 2005 11:54:33 -0400, Roy Smith <[EMAIL PROTECTED]> wrote: > And the correlary wart in Python is that the first argument to a > method is not required to be called "self". The vast majority of > people use "self", but every once in a great while you run into some > yahoo who feels this is