Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71905

Re: All-numeric script names and import

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <xdegaye@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.020
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'inserted': 0.09; 'name?': 0.09; 'subject:script': 0.09; 'python': 0.11; '2.7': 0.14; 'question.': 0.14; 'dumb.': 0.16; 'itself,': 0.16; 'subject:import': 0.16; 'xavier': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'app': 0.19; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'looks': 0.24; 'least': 0.26; 'header :In-Reply-To:1': 0.27; 'chris': 0.29; 'on,': 0.29; '(this': 0.29; "doesn't": 0.30; 'statement': 0.30; "i'm": 0.30; 'file': 0.32; 'skip:m 30': 0.32; 'skip:_ 10': 0.34; "can't": 0.35; 'something': 0.35; 'form.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'acceptable': 0.36; 'possible': 0.36; 'should': 0.36; 'application': 0.37; 'being': 0.38; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'tell': 0.60; 'back': 0.62; 'name': 0.63; 'answer.': 0.68; 'imp': 0.84; 'subject:All': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=9C7T34fIiML/Pk5FdaWoMskimFRmPuIzDM41ywd0n1Q=; b=EgShDChdGbQLObWdiFLBhz1gvw3wAaKokoJfn86hx6fnnRDx+R9K3bJAIl2YwxkmW6 m1hjD4rHsibM0wx1DBZLTFxPEhIKindyga0gGmvQp2qsyq0k5THJ78vdbxmqgvgFYXUv KDIsirBwEHhbuiMeA883qTp+n0+mAmGIT4/lFEef5jr5EJ9s5xOtdcp/WyvE9hJ3HsH5 dMvCe+czD/u8Fq7DYMNhSzciUuUOQ/pvf+YnV1Vir9b9JgDJilXB+BjILsFQLd8j9BST ZZnPVSYkAV/karairSOyMfq+n784mBBX2txdskOB6xiqnr3MEHQbvN4KS7JN8P2bOl/j SdDw==
X-Received by 10.180.90.51 with SMTP id bt19mr15819988wib.22.1400754754881; Thu, 22 May 2014 03:32:34 -0700 (PDT)
Date Thu, 22 May 2014 12:32:28 +0200
From Xavier de Gaye <xdegaye@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: All-numeric script names and import
References <CAPTjJmoadqpS0O-15We7xi7SzFCVxTFe1TU8hConcGZzxTRdcA@mail.gmail.com>
In-Reply-To <CAPTjJmoadqpS0O-15We7xi7SzFCVxTFe1TU8hConcGZzxTRdcA@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Mailman-Approved-At Thu, 22 May 2014 19:37:38 +0200
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 <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.10228.1400780259.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1400780259 news.xs4all.nl 2874 [2001:888:2000:d::a6]:58127
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71905

Show key headers only | View raw


On 05/21/2014 03:46 PM, Chris Angelico wrote:
 > If I have a file called 1.py, is there a way to import it? Obviously I
 > can't import it as itself, but in theory, it should be possible to
 > import something from it. I can manage it with __import__ (this is
 > Python 2.7 I'm working on, at least for the moment), but not with the
 > statement form.
 >
 > # from 1 import app as application # Doesn't work with a numeric name
 > application = __import__("1").app
 >
 > Is there a way to tell Python that, syntactically, this thing that
 > looks like a number is really a name? Or am I just being dumb?
 >
 > (Don't hold back on that last question. "Yes" is a perfectly
 > acceptable answer. But please explain which of the several
 > possibilities is the way I'm being dumb. Thanks!)
 >
 > ChrisA
 >

import 1.py as module_1 on Python 2.7 (module_1 is not inserted in sys.modules):

 >>> import imp
 >>> module_1 = imp.new_module('module_1')
 >>> execfile('1.py', module_1.__dict__)
 >>> del module_1.__dict__['__builtins__']

Xavier

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: All-numeric script names and import Xavier de Gaye <xdegaye@gmail.com> - 2014-05-22 12:32 +0200

csiph-web