Editing a function in-memory and in-place

bruno at modulix onurb at xiludom.gro
Thu Apr 27 10:50:36 EDT 2006


Peter Otten wrote:
(snip)
> 
> Can you cheat and just assign another known good func_code object?
>>>>def hello(): print "hello"
> ...
>>>>def world(): print "world"
> ...
>>>>def use_it(hello=hello, world=world):
> ...     hello()
> ...     world()
> ...
>>>>use_it()
> hello
> world
>>>>world.func_code = hello.func_code
>>>>use_it()
> hello
> hello
>>>>hello, world
> (<function hello at 0x402904fc>, <function world at 0x40290534>)

+1 H2OTW !-)

(NB : H2 -> Horrible Hack)

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list