Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32481
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail |
|---|---|
| From | Helmut Jarausch <jarausch@igpm.rwth-aachen.de> |
| Newsgroups | comp.lang.python |
| Subject | exec with partial globals |
| Date | 30 Oct 2012 12:00:03 GMT |
| Lines | 18 |
| Message-ID | <af9tq3FnmkaU1@mid.dfncis.de> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.dfncis.de s0kl5MawMpmWxEjDs3qSJg9J9vjzx7KdMr81BzpIYHf19a/yEbE/OTlQhbUyFqKSh1cOo3yMRj |
| Cancel-Lock | sha1:L59wXvYrOEWzJ5fedpYlMBf6ixk= |
| User-Agent | Pan/0.137 (The Mattel and Mars Bar Quick Energy Chocobot Hour; GIT 9a6aef1 git://git.gnome.org/pan2) |
| Xref | csiph.com comp.lang.python:32481 |
Show key headers only | View raw
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