[Tutor] __init__ arguments storage

Alan Gauld alan.gauld at btinternet.com
Sat Sep 20 20:40:50 CEST 2008


"Rob Kirkpatrick" <robert.d.kirkpatrick at gmail.com> wrote

> In between an object's creation and call to __init__, where are the 
> __init__
> arguments stored?  Is there a class dictionary that init uses to 
> initialize
> the instance?  I tried printing Class.__init__, but they aren't in 
> there.

I haven't checked Pythons source code but most languasges
hold the arguments to functions on the stack. So when the
function gets called it just pops them off the stack into local
variables.

> The reason I ask is that I was trying to track down a bug where it 
> looked
> like an argument was being mis-passed and I wanted to use pdb to see 
> how it
> was handled pre- and post-init.

I think you can safely assume that Python is passing your variables
from the Class creation call to the init method OK. Any such problems
would have been picked up and fixed a long time ago.

However there are some oddities around default values so if thats the
case with your parameters then you might see some behaviour you
don't expect.

Can you write a short puiece of code that reproduces the problem?
Then we might be able to offer more specific help.


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list