Re: exec with partial globals

2012-10-30 Thread Dave Angel
On 10/30/2012 08:57 AM, Helmut Jarausch wrote: > On Tue, 30 Oct 2012 08:33:38 -0400, Dave Angel wrote: > >> On 10/30/2012 08:00 AM, Helmut Jarausch wrote: >>> Hi, >>> >>> I'd like to give the user the ability to enter code which may only rebind >>> a given set of names but not all ones. >>> This do

Re: exec with partial globals

2012-10-30 Thread Chris Angelico
On Tue, Oct 30, 2012 at 11:57 PM, Helmut Jarausch wrote: > Given spreadsheet S (Source) and D (Destination) as objects (wrapping a > dictionary) a possible (legal) input would be > > D.price= D.price-S.discount > > No other fields of 'D' should be modifiable. That's a bit harder. What you're des

Re: exec with partial globals

2012-10-30 Thread Helmut Jarausch
On Tue, 30 Oct 2012 08:33:38 -0400, Dave Angel wrote: > On 10/30/2012 08:00 AM, Helmut Jarausch wrote: >> Hi, >> >> I'd like to give the user the ability to enter code which may only rebind >> a given set of names but not all ones. >> This does NOT work >> A=1 >> B=2 >> Code=compile('A=7','','exec

Re: exec with partial globals

2012-10-30 Thread Dave Angel
On 10/30/2012 08:00 AM, Helmut Jarausch wrote: > Hi, > > I'd like to give the user the ability to enter code which may only rebind > a given set of names but not all ones. > This does NOT work > A=1 > B=2 > Code=compile('A=7','','exec') > exec(Code,{'A':0}) > print("I've got A={}".format(A)) # prin

Re: exec with partial globals

2012-10-30 Thread Chris Angelico
On Tue, Oct 30, 2012 at 11:00 PM, Helmut Jarausch wrote: > Hi, > > I'd like to give the user the ability to enter code which may only rebind > a given set of names but not all ones. > > How can 'filter' the gobal namespace such that modifying 'A' is allowed > but any attempt to modify 'B' should g

exec with partial globals

2012-10-30 Thread Helmut Jarausch
Hi, I'd like to give the user the ability to enter code which may only rebind a given set of names but not all ones. This does NOT work A=1 B=2 Code=compile('A=7','','exec') exec(Code,{'A':0}) print("I've got A={}".format(A)) # prints 1 How can 'filter' the gobal namespace such that modifying 'A