Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109906
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Michael Selik <michael.selik@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Conversion: execfile --> exec |
| Date | Mon, 13 Jun 2016 17:18:06 +0000 |
| Lines | 33 |
| Message-ID | <mailman.43.1465838297.2288.python-list@python.org> (permalink) |
| References | <CAKyEaCuhNhRudhV_xMo6WGnePdjFvcZ=R2eDru7JjQUoHgB+tQ@mail.gmail.com> <b0590f59-7c17-3f69-f05a-6bfae53f8824@mrabarnett.plus.com> <mailman.40.1465827079.2288.python-list@python.org> <2ff66017-2c20-40eb-8e9d-853b33ec239b@googlegroups.com> <CAGgTfkPtvFgTEpgz=vKCrZtu2_KxozacLFzGsGK_E3LpfGu5+Q@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de mEeDp0Fe7+ERdAnkUxn8pg3PTeqJDTMzDA8xoHFoPWoQ== |
| Return-Path | <michael.selik@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'mrab': 0.05; 'thread': 0.10; 'python': 0.10; '2016': 0.16; 'general.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '>': 0.18; 'email addr:gmail.com>': 0.18; 'to:2**1': 0.21; 'saying': 0.22; '2.x': 0.22; '3.x': 0.22; 'file:': 0.22; 'pass': 0.22; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'module': 0.25; 'command': 0.26; 'wonder': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'object,': 0.27; "skip:' 10": 0.28; '13,': 0.29; 'referencing': 0.29; 'convert': 0.29; 'skip:- 30': 0.32; 'problem': 0.33; 'source': 0.33; 'open': 0.33; 'file': 0.34; 'info': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'received:209.85': 0.36; 'monday,': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'thanks': 0.37; 'received:209': 0.38; 'skip:- 20': 0.39; 'does': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'more': 0.63; 'info)': 0.84; 'utc+5:30,': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Cei2lQL442bTVgC+JIfk8E2nqsus6Zx94TsFOuIWv/o=; b=dzdVQynHOpLBdxTVmoChzxuizgeuEb40dYSfyVS4svHggZqupOgt/tYl9AIOHlDwdl fINvqtYJ7UNKeyAJWj5mE9vMOgWW0NyJrtfZfO2A5mZDl5wpgAIvniGybbFDdMcc4IZD fZrpwxyf09Vfbp6qAetzLK2GUxsF2tBIuV/GTEVpjCQD61LHHqCX1f3OuRE6L4tU3p3U mZSW0QuDvIJxLn6ZsAw2eB4cXshUXV/pYQlDLAZD6jMY9cdmxrGHwHemoudLWc3J5ECc imMQEm0PKcYANNcsAxzKMqObICbAmq5dHWtB7AZU8hXSusGRkdZLu/2+bQsNUPlRlw6+ WjAg== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Cei2lQL442bTVgC+JIfk8E2nqsus6Zx94TsFOuIWv/o=; b=mxvuSrz1+vahcMpW1oXzKfTEmHMc5ZcY2n4riSKn26dYhVec3XNfPmVtQmLasb4UE3 e0+6hpqnl2vgN0v6DgOQQoMNp2na3fwv/k8qS5WA4nfWlzCj2uvdGLkWyorJy4A72ClK 76VNTYem2d/Qq83ih/aO14Dqy+jupJAsjThhc4lTy5ii+yvUxqE3WhTxe1SJ2SNBbKiz mewmvRjiy83Yv2M3oP8AbCvfHAASiDv/NwQehs6ZXoqfCsaTvNJDly1axZh+DPpDwYBj 3bVqszXzTJnoo9KZOvhZuQG6bJe0Li/feO9/7Vya2uiC+7+gSGTX/iCkukmwdnTloaFS isCw== |
| X-Gm-Message-State | ALyK8tKZbcBkWJktYFbl0ax5rfG+WfJi/2TFkoldUXCBElPidUdzZpY3+P5s259O5lSfIuALnpeTFpJSkAajNA== |
| X-Received | by 10.140.41.164 with SMTP id z33mr5060837qgz.54.1465838295786; Mon, 13 Jun 2016 10:18:15 -0700 (PDT) |
| In-Reply-To | <2ff66017-2c20-40eb-8e9d-853b33ec239b@googlegroups.com> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.22 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| 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> |
| X-Mailman-Original-Message-ID | <CAGgTfkPtvFgTEpgz=vKCrZtu2_KxozacLFzGsGK_E3LpfGu5+Q@mail.gmail.com> |
| X-Mailman-Original-References | <CAKyEaCuhNhRudhV_xMo6WGnePdjFvcZ=R2eDru7JjQUoHgB+tQ@mail.gmail.com> <b0590f59-7c17-3f69-f05a-6bfae53f8824@mrabarnett.plus.com> <mailman.40.1465827079.2288.python-list@python.org> <2ff66017-2c20-40eb-8e9d-853b33ec239b@googlegroups.com> |
| Xref | csiph.com comp.lang.python:109906 |
Show key headers only | View raw
On Mon, Jun 13, 2016, 10:36 AM Rustom Mody <rustompmody@gmail.com> wrote:
> On Monday, June 13, 2016 at 7:41:33 PM UTC+5:30, MRAB wrote:
> > On 2016-06-13 14:24, Long Yang wrote:
> > > The python 2.x command is as following:
> > > ---------------------------
> > > info = {}
> > > execfile(join('chaco', '__init__.py'), info)
> > > ------------------------------
> > >
> > > But execfile has been removed in python 3.x.
> > > So my problem is how to convert the above to a 3.x based command?
> > >
> > > thanks very much
> > >
> > Open the file and pass it to exec:
> >
> > info = {}
> > with open(join('chaco', '__init__.py')) as file:
> > exec(file.read(), info)
>
>
> I wonder whether this should use importlib instead [yeah really
> wondering...
> not a rhetorical question]
>
> See slide 38-40 http://www.slideshare.net/pydanny/python-worst-practices
The slides you're referencing are saying importlib is better than exec'ing
an import. The question of this thread was more general. An import makes a
module object, but exec'ing arbitrary source does not (unless it uses
import).
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Conversion: execfile --> exec MRAB <python@mrabarnett.plus.com> - 2016-06-13 15:11 +0100
Re: Conversion: execfile --> exec Rustom Mody <rustompmody@gmail.com> - 2016-06-13 07:31 -0700
Re: Conversion: execfile --> exec Michael Selik <michael.selik@gmail.com> - 2016-06-13 17:18 +0000
Re: Conversion: execfile --> exec Rustom Mody <rustompmody@gmail.com> - 2016-06-13 10:45 -0700
Re: Conversion: execfile --> exec Michael Selik <michael.selik@gmail.com> - 2016-06-13 22:14 +0000
csiph-web