Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29548
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <kwatch@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:code': 0.07; 'subject:How': 0.09; 'macos': 0.09; 'python:': 0.09; 'received :mail-qc0-f174.google.com': 0.09; 'def': 0.10; '2.7.3': 0.16; 'globals(),': 0.16; 'os:': 0.16; 'subject:object': 0.16; 'variables': 0.17; 'sender:addr:gmail.com': 0.18; 'subject:] ': 0.19; 'trying': 0.21; 'message-id:@mail.gmail.com': 0.27; 'actual': 0.28; 'run': 0.28; "i'm": 0.29; 'code': 0.31; 'to:addr :python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'expected': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'subject:with': 0.36; 'possible': 0.37; 'subject:[': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'object': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=oAcRPLzGpp06zxvwVFFscZs4o1/vRo/BWaf2jJJrQco=; b=IjT5MhdLWu0AHunZS4jBNCrPithiFtZMujB/c7U69VSaDv9y7RPwSuqOwqomGE0OYg DREI6deCC/fHrxB+6P/WRSuXpKi+gXi6woVX17bFDwu16ygScOXJVylN8LM2Crdo7Icw Nlr+xIUal4Fff6xpO1shNSUJDy88Fs2h6pzkglagrXYL1+PpDzNyalbrhZhGYn2GoKY3 Q7OSgflpAGNJ1nPYDozPj+piX0mwK7NVucnl8x8lsmrlQjX3FFm2aULbefundOGRdOFu s1ArlYr6JLU2v5owOG6aU6fYA/KAZVo3JNQhnPsaYQRv6M07vQEpgnPZBcfSsj1wfiiD kxGg== |
| MIME-Version | 1.0 |
| Sender | kwatch@gmail.com |
| Date | Thu, 20 Sep 2012 20:27:37 +0900 |
| X-Google-Sender-Auth | AiSbCOODnFAOPaHn3wMgCpIR384 |
| Subject | [Q] How to exec code object with local variables specified? |
| From | Makoto Kuwata <kwa@kuwata-lab.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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.955.1348140460.27098.python-list@python.org> (permalink) |
| Lines | 20 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1348140460 news.xs4all.nl 6938 [2001:888:2000:d::a6]:39643 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:29548 |
Show key headers only | View raw
Hi,
Is it possible to run code object with local variables specified?
I'm trying the following code but not work:
def fn():
x = 1
y = 2
localvars = {'x': 0}
exec(fn.func_code, globals(), localvars)
print(localvars)
## what I expected is: {'x': 1, 'y': 2}
## but actual is: {'x': 0}
Python: 2.7.3
OS: MacOS X
--
regards,
makoto kuwata
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
[Q] How to exec code object with local variables specified? Makoto Kuwata <kwa@kuwata-lab.com> - 2012-09-20 20:27 +0900 Re: [Q] How to exec code object with local variables specified? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-21 13:20 -0700 Re: [Q] How to exec code object with local variables specified? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-21 13:20 -0700
csiph-web