Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34714
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'rename': 0.07; 'scripts': 0.09; 'subject:How': 0.09; 'portable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'restriction': 0.09; 'subject:module': 0.09; 'subject:number': 0.09; 'anyway': 0.11; '"from': 0.16; '"import': 0.16; 'identifier.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'subject:import': 0.16; 'underscore.': 0.16; 'wrote:': 0.17; 'hack': 0.18; 'saying': 0.18; 'module': 0.19; 'import': 0.21; 'skip:_ 20': 0.22; 'script': 0.24; 'tried': 0.25; 'header:User- Agent:1': 0.26; 'instead.': 0.27; 'header:X-Complaints-To:1': 0.28; 'file': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'your': 0.60 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: How to import module whose filename starts number |
| Date | Wed, 12 Dec 2012 18:57:29 +0100 |
| Organization | None |
| References | <39662302-5d9c-44fe-8ed2-e96bbca08714@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p5084abfa.dip.t-dialin.net |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.790.1355334990.29569.python-list@python.org> (permalink) |
| Lines | 19 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1355334990 news.xs4all.nl 6966 [2001:888:2000:d::a6]:56781 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:34714 |
Show key headers only | View raw
Yong Hu 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?
Or an underscore. The module name must be a valid identifier. In CPython you
can hack around that restriction with
step01 = __import__("01_step1")
but this "solution" is not portable and I recommend that you rename your
scripts instead.
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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