Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96030
| Path | csiph.com!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'globals': 0.09; 'namespace': 0.09; 'script,': 0.09; 'stack': 0.13; 'def': 0.13; 'explicitly': 0.15; '1:48': 0.16; 'fancy': 0.16; 'php)': 0.16; 'wrote:': 0.16; '2015': 0.20; 'sep': 0.22; 'sorry,': 0.22; 'passing': 0.23; 'this:': 0.23; 'header:In-Reply- To:1': 0.24; 'script': 0.25; "doesn't": 0.26; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'inspect': 0.29; 'probably': 0.31; 'another': 0.32; 'statement': 0.32; 'received:google.com': 0.35; 'could': 0.35; 'something': 0.35; 'instead': 0.36; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'takes': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'more': 0.63; 'locals': 0.84; 'to:name:python': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=gQ2ybWX8nfFEYPXHn9SQJBeLO9GwJ2yUQ47lXkeLWB4=; b=TCVCvaAaZ6Xx+l/b/3JZvh++mCVdR0d6Glr7RR3I9s22bBg2xxbWxpzC2xe4UD/B9f ci+1jZwgUyw8BRtK8PFqkiEqLJo3q1ESZV6+LoaY820nKLVvpLP6xrNuUYOr+sFpAQ8H dqGV3tBSdXccyLL7vNsdLy3wXhoP4FGKq/k3s+ms4jcJ2GSVfM5A7eeApf+fexQ6OgIV eBgUN7ZIYeF7Bxe0NCZcakhff+GUWW0LzQqjkJBn2V+9fDZNAKHqBngp6SkMbZzRnNi0 bVJWvJ9kfUQXjFNM1UY3vACXiHj+6Mf6KHLqfDZbeNdurFIGHBtSUJ5zZqNX6WJsl3FM g3rw== |
| X-Received | by 10.129.45.194 with SMTP id t185mr6496288ywt.111.1441396381602; Fri, 04 Sep 2015 12:53:01 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <CALwzid=MTtd6r=0WfX=ohU_tuEgjQjF8qr+_mrX=amjByOiA2g@mail.gmail.com> |
| References | <c3363$547e74fe$5419aafe$24179@news.ziggo.nl> <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <CALwzid=MTtd6r=0WfX=ohU_tuEgjQjF8qr+_mrX=amjByOiA2g@mail.gmail.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Fri, 4 Sep 2015 13:52:22 -0600 |
| Subject | Re: Python handles globals badly. |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.147.1441396389.8327.python-list@python.org> (permalink) |
| Lines | 20 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1441396389 news.xs4all.nl 23816 [2001:888:2000:d::a6]:39355 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:96030 |
Show key headers only | View raw
On Fri, Sep 4, 2015 at 1:48 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Fri, Sep 4, 2015 at 1:11 PM, <tdev@freenet.de> wrote:
>> 6- "include" script statement (extending namespace to another script, like PHP)
>
> def include(filename):
> exec(open(filename).read())
Sorry, that doesn't work because it takes locals from the include
function. You probably need something more like this:
def include(filename, globals):
exec(open(filename).read(), globals)
To be called like:
include("foo.py", globals())
If you want to get fancy you could probably have include inspect the
stack to pull the globals from the parent stack frame instead of
explicitly passing them in.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Python handles globals badly. tdev@freenet.de - 2015-09-04 12:11 -0700
Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-04 13:48 -0600
Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-04 13:52 -0600
Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2015-09-05 10:27 +1000
Re: Python handles globals badly. Michael Torrie <torriem@gmail.com> - 2015-09-04 19:42 -0600
Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2015-09-05 11:54 +1000
Program in or into (was Python handles globals badly) Rustom Mody <rustompmody@gmail.com> - 2015-09-04 20:18 -0700
Re: Program in or into (was Python handles globals badly) Chris Angelico <rosuav@gmail.com> - 2015-09-05 13:31 +1000
Re: Program in or into (was Python handles globals badly) Steven D'Aprano <steve@pearwood.info> - 2015-09-06 12:35 +1000
Re: Program in or into (was Python handles globals badly) MRAB <python@mrabarnett.plus.com> - 2015-09-06 03:54 +0100
Re: Program in or into (was Python handles globals badly) Rustom Mody <rustompmody@gmail.com> - 2015-09-05 21:35 -0700
Re: Program in or into (was Python handles globals badly) random832@fastmail.us - 2015-09-06 01:26 -0400
Re: Program in or into (was Python handles globals badly) wxjmfauth@gmail.com - 2015-09-06 00:42 -0700
Re: Program in or into (was Python handles globals badly) Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-06 18:19 -0600
csiph-web