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


Groups > comp.lang.python > #71858

Re:All-numeric script names and import

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'name?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'underscore': 0.09; 'python': 0.11; 'wrote': 0.14; '2.7': 0.14; 'question.': 0.14; 'dotted_name': 0.16; 'dumb.': 0.16; 'itself,': 0.16; 'name]': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:import': 0.16; 'followed': 0.16; 'obviously': 0.18; 'app': 0.19; 'import': 0.22; 'looks': 0.24; 'question': 0.24; 'least': 0.26; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'on,': 0.29; '(this': 0.29; "doesn't": 0.30; 'document.': 0.30; 'statement': 0.30; "i'm": 0.30; 'page.': 0.31; 'file': 0.32; 'url:python': 0.33; 'continuing': 0.33; 'skip:_ 10': 0.34; "can't": 0.35; 'something': 0.35; 'definition': 0.35; 'form.': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'acceptable': 0.36; 'possible': 0.36; 'url:org': 0.36; 'should': 0.36; 'application': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'tell': 0.60; 'back': 0.62; 'name': 0.63; 'more': 0.64; 'answer.': 0.68; 'as:': 0.81; 'subject:All': 0.84; 'url:reference': 0.84; 'subject::': 0.85
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re:All-numeric script names and import
Date Wed, 21 May 2014 10:32:23 -0400 (EDT)
Organization news.gmane.org
References <CAPTjJmoadqpS0O-15We7xi7SzFCVxTFe1TU8hConcGZzxTRdcA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host dpc6744192053.direcpc.com
X-Newsreader PiaoHong.NewsGroup.Client.VIP:1.52
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.10193.1400682734.18130.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1400682734 news.xs4all.nl 2944 [2001:888:2000:d::a6]:47244
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71858

Show key headers only | View raw


Chris Angelico <rosuav@gmail.com> Wrote in message:
> 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!)
> 

I don't think there's any question of dumbhood,  but the answer
 should be found in the formal grammar document. 

https://docs.python.org/2/reference/grammar.html

The import statement is defined as:
   
import_name: 'import' dotted_as_names

and dotted_as_names is defined as:

dotted_as_names: dotted_as_name (',' dotted_as_name)*

continuing thusly:

import_as_name: NAME ['as' NAME]
dotted_as_name: dotted_name ['as' NAME]

So it comes down to the definition of NAME, which doesn’t seem to
 be on that page. That's the one which has to start with
 underscore or letter,  followed by zero or more letter,  digits,
 ...





-- 
DaveA

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


Thread

Re:All-numeric script names and import Dave Angel <davea@davea.name> - 2014-05-21 10:32 -0400

csiph-web