Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38748
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.023 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'exec': 0.07; 'variables.': 0.07; 'python': 0.09; 'assigning': 0.09; 'modifies': 0.09; 'subject:Python3': 0.09; "'),": 0.16; 'local.': 0.16; 'syntax.': 0.16; 'wrote:': 0.17; 'variables': 0.17; 'changes': 0.20; 'names.': 0.22; "i've": 0.23; 'testing': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'am,': 0.27; 'skip:e 30': 0.27; "doesn't": 0.28; 'skip:_ 10': 0.29; 'e.g.': 0.30; 'function': 0.30; 'could': 0.32; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'changed': 0.34; 'doing': 0.35; 'add': 0.36; 'but': 0.36; "didn't": 0.36; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'back': 0.62; 'necessarily': 0.63; 'within': 0.64; 'received:74.208': 0.71; 'transfer': 0.76; 'subject:this': 0.84; 'everything.': 0.84; 'locals': 0.84; 'net.': 0.91 |
| Date | Tue, 12 Feb 2013 08:27:41 -0500 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Python3 exec locals - this must be a FAQ |
| References | <anuoc6F8kvaU1@mid.dfncis.de> |
| In-Reply-To | <anuoc6F8kvaU1@mid.dfncis.de> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:8WGSlemmuVKfHTScrk7nLmBbL93RG9Ayljpy5aAykZc 2x/pdMuBgeCO1KneS8w+XpnWzr3ui8h4S9UOSssCrluVLZ2/Xp pm8MrvW0vue3KuWVitBADHMWt0wIKt9vbvvzL2jSYdLU52txCi E32Lc92t0oEvqDwNr7M9hWdqvgFvrzNcA2mB1xmUHOL3Rezn3l n3F10cc+knTmOtOgeKQX9BaVrrdeMDvqagxxQ7TCiVrs2nhHhM hO0nCE9fzL2bjzW/G2CQPh+VyiyrDi7ZfR0AJ+imRa+Y5P654o +teM8eNYThbZt1uXPcQ0DJtNAMF9xszr98OHhoRGRdt0vgoSQ= = |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1699.1360675679.2939.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360675679 news.xs4all.nl 6874 [2001:888:2000:d::a6]:52279 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38748 |
Show key headers only | View raw
On 02/12/2013 06:46 AM, Helmut Jarausch wrote:
> Hi,
>
> I've tried but didn't find an answer on the net.
>
> The exec function in Python modifies a copy of locals() only.
> How can I transfer changes in that local copy to the locals of my function
> ** without ** knowing the names of these variables.
>
> E.g. I have a lot of local names.
>
> Doing
>
> _locals= locals()
This doesn't copy everything. But perhaps you know that and you're just
testing us.
> expr=compile(input('statements assigning to some local variables '),
> 'user input','exec')
> exec(expr,globals(),_locals)
>
> How can I "copy" the new values within _locals to my current locals.
>
> If I knew that Var1 has changed I could say
> Var1 = _locals['Var1'] but what to do in general?
locals()["Var1"] = _locals["Var1"] will set the same Var1 local.
So you might write a loop on _locals.
But beware if someone has deleted one of the "variables" it may not do
what you'd like. You cannot necessarily add back a local with the above
syntax.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python3 exec locals - this must be a FAQ Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-02-12 11:46 +0000
Re: Python3 exec locals - this must be a FAQ Dave Angel <davea@davea.name> - 2013-02-12 08:27 -0500
Re: Python3 exec locals - this must be a FAQ Helmut Jarausch <jarausch@skynet.be> - 2013-02-12 14:29 +0000
Re: Python3 exec locals - this must be a FAQ Dave Angel <davea@davea.name> - 2013-02-12 10:40 -0500
Re: Python3 exec locals - this must be a FAQ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-13 11:05 +1100
Re: Python3 exec locals - this must be a FAQ MRAB <python@mrabarnett.plus.com> - 2013-02-12 15:15 +0000
Re: Python3 exec locals - this must be a FAQ Terry Reedy <tjreedy@udel.edu> - 2013-02-12 10:50 -0500
Re: Python3 exec locals - this must be a FAQ Dave Angel <davea@davea.name> - 2013-02-12 11:40 -0500
csiph-web