Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34715

Re: How to import module whose filename starts number

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <bsk16@case.edu>
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; 'assign': 0.07; 'scripts': 0.09; 'subject:How': 0.09; 'restriction': 0.09; 'subject:module': 0.09; 'subject:number': 0.09; 'cc:addr:python-list': 0.10; 'anyway': 0.11; 'resulting': 0.13; 'dec': 0.15; '"from': 0.16; '"import': 0.16; 'cc:name:python list': 0.16; 'identifiers.': 0.16; 'subject:import': 0.16; 'wrote:': 0.17; 'saying': 0.18; 'module': 0.19; 'email addr:gmail.com&gt;': 0.20; 'import': 0.21; 'cc:2**0': 0.23; '&gt;': 0.23; 'script': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'url:mailman': 0.29; 'skip:& 10': 0.29; 'url:python': 0.32; 'file': 0.32; 'url:listinfo': 0.32; 'another': 0.33; 'received:google.com': 0.34; 'there': 0.35; 'received:74.125': 0.36; 'url:org': 0.36; '12,': 0.36; 'header:Received:9': 0.36; 'subject:: ': 0.38; 'object': 0.38; 'skip:" 10': 0.40; 'url:mail': 0.40; 'believe': 0.69
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-gm-message-state; bh=TNYDxJ2HRJW/y9zxyodE679yJv3385CnoxM65edcsDk=; b=JeKT1ABAqkHrVlUSc7Rw/AmYgpcR9IS43t02yI3lWRzveQzv2EVm3h+r1EoDLN9KA6 QckIBUIoq2q0OItGDAdzGZQ0MKlww1Kv3TC+lE92FpuLUtgruGjjK03tZKBZPotKaoXl RwjExM8U/77kha56mK9TDZF+krbbhpECOpbFXc7x6P4NQA3+1CdIBIYMbpSWU5KJ24Th sDwf2RUyOKQLPTOlPLwW2kjtq9pSC+I0x01MqBv/hMiMpWD205aZrrbyWfuFklDs5q95 lc1QELmhr+HbrPf2SZWdJHdotJgNU1achVF7jGhk43vMgbNvmtV5POS0eq8UbeIwLilD agTA==
MIME-Version 1.0
In-Reply-To <39662302-5d9c-44fe-8ed2-e96bbca08714@googlegroups.com>
References <39662302-5d9c-44fe-8ed2-e96bbca08714@googlegroups.com>
Date Wed, 12 Dec 2012 09:50:42 -0800
Subject Re: How to import module whose filename starts number
From Benjamin Kaplan <benjamin.kaplan@case.edu>
To Yong Hu <yhu221300@gmail.com>
Content-Type multipart/alternative; boundary=bcaec5555678f177f404d0ab6f60
X-Gm-Message-State ALoCoQkZceEr8dk+ikw42VDVvbFvY/qjguwa57mUrrx/TbGnxJcDysrgJjfIFBjcX7GlvqQsmrvjJxtR/idfsD/71DY6oAGIKivQawqbdMgkdXu9oAvDQJqTpDN1+oSItaytTw2RaXpMUvMG45CklOyy8jdwrnI2zQ==
X-Junkmail-Whitelist YES (by domain whitelist at mpv1.tis.cwru.edu)
Cc Python List <python-list@python.org>
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.791.1355335029.29569.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355335030 news.xs4all.nl 6852 [2001:888:2000:d::a6]:57432
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34715

Show key headers only | View raw


[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 | NextPrevious in thread | Find similar | Unroll thread


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