[Tutor] __init__ arguments storage

Rob Kirkpatrick robert.d.kirkpatrick at gmail.com
Sat Sep 20 22:30:03 CEST 2008


Thanks Kent!  That really makes it clear now.

The bug I ran into was a while back and I've since ignored it to the point
of forgetting how to invoke it, but I remember the stack trace said
something about "variable received multiple arguments".  I wanted to check
the arguments to see if the same variable was being passed twice, and if so,
which one was being used.

The whole issue of how the class call stored the init args was keeping me up
at night even though I didn't care about the original error anymore.  It
bugged me enough, I posted and true to form got an awesome (and very quick)
reply.

Thanks again!

Rob


On Sat, Sep 20, 2008 at 12:44 PM, Kent Johnson <kent37 at tds.net> wrote:

> On Sat, Sep 20, 2008 at 1:32 PM, Rob Kirkpatrick
> <robert.d.kirkpatrick at gmail.com> wrote:
> > Hi All,
> >
> > 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.
>
> No, there is no class dictionary like this. The arguments are stored
> as ordinary function call parameters.
>
> This message and the followup give a pretty good overview of what
> happens when you create a new class instance:
> http://mail.python.org/pipermail/python-list/2005-November/349806.html
>
> The implementation of this is in the __call__() method of the
> metaclass of the class being created. Normally this is 'type'. If you
> want the gory details, the implementation of type.__call__() is in the
> type_call() function of typeobject.c.
>
> http://svn.python.org/view/python/trunk/Objects/typeobject.c?rev=66043&view=auto
>
> > 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.
>
> Show us the code...it's unlikely that this is a problem with the
> interpreter.
>
> Kent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080920/ae074eb5/attachment.htm>


More information about the Tutor mailing list