Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32481
| From | Helmut Jarausch <jarausch@igpm.rwth-aachen.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | exec with partial globals |
| Date | 2012-10-30 12:00 +0000 |
| Message-ID | <af9tq3FnmkaU1@mid.dfncis.de> (permalink) |
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' is allowed
but any attempt to modify 'B' should give an exception.
Many thanks for a hint,
Helmut.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
exec with partial globals Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2012-10-30 12:00 +0000
Re: exec with partial globals Chris Angelico <rosuav@gmail.com> - 2012-10-30 23:28 +1100
Re: exec with partial globals Dave Angel <d@davea.name> - 2012-10-30 08:33 -0400
Re: exec with partial globals Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2012-10-30 12:57 +0000
Re: exec with partial globals Chris Angelico <rosuav@gmail.com> - 2012-10-31 00:18 +1100
Re: exec with partial globals Dave Angel <d@davea.name> - 2012-10-30 09:39 -0400
csiph-web