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


Groups > comp.lang.python > #71858 > unrolled thread

Re:All-numeric script names and import

Started byDave Angel <davea@davea.name>
First post2014-05-21 10:32 -0400
Last post2014-05-21 10:32 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#71858 — Re:All-numeric script names and import

FromDave Angel <davea@davea.name>
Date2014-05-21 10:32 -0400
SubjectRe:All-numeric script names and import
Message-ID<mailman.10193.1400682734.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web