How to import module whose filename starts number

Benjamin Kaplan benjamin.kaplan at case.edu
Wed Dec 12 18:50:42 CET 2012


On Dec 12, 2012 9:47 AM, "Yong Hu" <yhu221300 at gmail.com> wrote:
>
> I have a few scripts whose file names start with numbers. For example,
01_step1.py, 02_step2.py
>
> I tried to import them in another script by "import 01_step1" or "from
01_step1 import *". Both failed, saying "SyntaxError: invalid syntax"
>
> Is there anyway to import those files? The file name must start with
characters?
> --

I believe the restriction is that the module names must be valid
identifiers. You may still be able to import them using __import__ and then
assign the resulting module object to a valid name.
> http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121212/743c76c9/attachment.html>


More information about the Python-list mailing list