often. I'm wondering if it's possible to query an object instance to find
out what arguments the instance's __init__ function was called with from
*outside* the class's local namespace. For example, if I define a class Foo
as follows:
import sys
class Foo:
def __init__(self, *args):
print args # no problem here
....and then create an instance of Foo:
someobj = Foo('bar', 'bleck') ('bar', 'bleck')
Now, I'd like to be able to find out what arguments someobj was called with.
So first I tried:
print someobj.args
but I get: "AttributeError: args"
so then I tried:
print some_obj.__init__.func_defaults
which returns an empty tuple
and then I tried:
some_obj.__dict__['args']
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
KeyError: args
No dice.. Is there any way to find out what arguments an object was called
with? Are the args stored with the instance? I scoured the python faq but
there are no answers (that I could see) to this question. Any help would be
much appreciated.
yours,
Alex Eberts