All-numeric script names and import

Chris Angelico rosuav at gmail.com
Wed May 21 09:46:46 EDT 2014


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



More information about the Python-list mailing list