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 r

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 "", line 1, in 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 ... >>> functi

Re: eval() and global variables

2008-12-16 Thread Juan Pablo Romero Méndez
P 2008/12/16 : > Quoth "=?ISO-8859-1?Q?Juan_Pablo_Romero_M=E9ndez?=" : >> 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: >> >> eva