Module names beginning w/ a digit
Erik Max Francis
max at alcyone.com
Thu Nov 7 22:29:50 EST 2002
"John E. Barham" wrote:
> Why can't Python module names start a digit?
Because names that start with digits aren't valid identifiers. Module
names can't be Python keywords, either:
max at oxygen:~/tmp% touch is.py
max at oxygen:~/tmp% python
Python 2.2.2 (#2, Oct 14 2002, 17:32:20)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import is
File "<stdin>", line 1
import is
^
SyntaxError: invalid syntax
As someone else pointed out, you can use the __import__ function which
takes a string, rather than an identifier. If it's something you plan
on using a lot, though, you're probably off giving it the name of a
legal Python identifier.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ The conviction of wisdom is the plague of man.
\__/ Montaigne
Church / http://www.alcyone.com/pyos/church/
A lambda calculus explorer in Python.
More information about the Python-list
mailing list