Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34715
| References | <39662302-5d9c-44fe-8ed2-e96bbca08714@googlegroups.com> |
|---|---|
| Date | 2012-12-12 09:50 -0800 |
| Subject | Re: How to import module whose filename starts number |
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.791.1355335029.29569.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On Dec 12, 2012 9:47 AM, "Yong Hu" <yhu221300@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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How to import module whose filename starts number Yong Hu <yhu221300@gmail.com> - 2012-12-12 09:42 -0800 Re: How to import module whose filename starts number Dave Angel <d@davea.name> - 2012-12-12 12:53 -0500 Re: How to import module whose filename starts number Peter Otten <__peter__@web.de> - 2012-12-12 18:57 +0100 Re: How to import module whose filename starts number Benjamin Kaplan <benjamin.kaplan@case.edu> - 2012-12-12 09:50 -0800
csiph-web