passing arguments to a code object?

Gregory Trubetskoy grisha at ispol.com
Mon Nov 13 17:57:50 EST 2000


[I know this is a really archane question]

If all I have is a code object that represents a function, is there a way
to call it and pass it arguments?

I am basically trying to execute a function in a context different from
which it was declared in.

E.g.:

def dog():

    def cat(a):
        print a

I can get the code object for cat() via something like:

consts  = dog.func_code.co_consts

for const in consts:
	if const.co_name == "cat"
		cat =  const
		break

Now, what should I do to call cat and pass it some value as "a"?

Any advice is much appreciated,

Grisha




More information about the Python-list mailing list