Why are functions atomic?

Duncan Booth duncan.booth at invalid.invalid
Tue May 1 11:17:48 EDT 2007


7stud <bbxx789_05ss at yahoo.com> wrote:

> Does deepcopy work?

It doesn't copy a function.

The easiest way to make a modified copy of a function is to use the 'new' 
module.

>>> def f(x=2): print "x=", x

>>> g = new.function(f.func_code, f.func_globals, 'g', (3,), 
f.func_closure)
>>> g()
x= 3
>>> f()
x= 2



More information about the Python-list mailing list