[Tutor] __init__ arguments storage
Kent Johnson
kent37 at tds.net
Sat Sep 20 21:44:17 CEST 2008
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
More information about the Tutor
mailing list