Defining a code object from a function
Steve Purcell
stephen_purcell at yahoo.com
Thu Apr 5 12:29:10 EDT 2001
Neil Benn wrote:
> I'm using the inspect module to get information about the method
> arguments back.
>
> However...................
>
> My problem is that the getargs methods of inspect want a code object.
> Looking through the docs on Python.org I can't work out how to convert a
> method call to a code object so that I can then get the arguments back.
>
> Please could someone advise me, pretty please?
Try this:
>>> import inspect
>>> class Foo:
... def method(self, arg1, arg2="something"):
... pass
...
>>> f = Foo()
>>> inspect.getargs(f.method.im_func.func_code)
(['self', 'arg1', 'arg2'], None, None)
-Steve
--
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo
More information about the Python-list
mailing list