Re: eval() and global variables

2008-12-19 Thread Peter Otten
Juan Pablo Romero Méndez wrote: The hack given by Peter works fine, except in this case: def (fn): ... f2 = lambda x,y:(x,y,fn(x,y)) ... function = type(f2) ... f3 = function(f2.func_code,dict()) ... print f3 ... (lambda x,y:x+y) Traceback (most recent call

Re: eval() and global variables

2008-12-18 Thread Juan Pablo Romero Méndez
The hack given by Peter works fine, except in this case: def (fn): ... f2 = lambda x,y:(x,y,fn(x,y)) ... function = type(f2) ... f3 = function(f2.func_code,dict()) ... print f3 ... (lambda x,y:x+y) Traceback (most recent call last): File stdin, line 1, in module File

Re: eval() and global variables

2008-12-17 Thread Peter Otten
Juan Pablo Romero Méndez wrote: Suppose this function is given: def f(x,y): return x+y+k Is it possible to somehow assign a value to k without resorting to making k global? You can replace the function's global dictionary: def f(x, y): ... return x+y+k ... function = type(f)

eval() and global variables

2008-12-16 Thread Juan Pablo Romero Méndez
Hello, Suppose this function is given: def f(x,y): return x+y+k Is it possible to somehow assign a value to k without resorting to making k global? I'm thinking something like this: eval(f(1,1), {f:f, k:1}) Or even better, something like: def g(k): return f g(1)(1,1) == 3 Regards,

eval() and global variables

2008-12-16 Thread rdmurray
Quoth =?ISO-8859-1?Q?Juan_Pablo_Romero_M=E9ndez?= jpablo.rom...@gmail.com: Hello, Suppose this function is given: def f(x,y): return x+y+k Is it possible to somehow assign a value to k without resorting to making k global? I'm thinking something like this: eval(f(1,1), {f:f,

Re: eval() and global variables

2008-12-16 Thread Juan Pablo Romero Méndez
P 2008/12/16 rdmur...@bitdance.com: Quoth =?ISO-8859-1?Q?Juan_Pablo_Romero_M=E9ndez?= jpablo.rom...@gmail.com: Hello, Suppose this function is given: def f(x,y): return x+y+k Is it possible to somehow assign a value to k without resorting to making k global? I'm thinking something