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


Groups > comp.lang.python > #34713

Re: How to import module whose filename starts number

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'python.': 0.02; 'scripts': 0.09; 'subject:How': 0.09; 'subject:module': 0.09; 'subject:number': 0.09; 'cc:addr:python-list': 0.10; 'anyway': 0.11; '"from': 0.16; '"import': 0.16; 'subject:import': 0.16; 'wrote:': 0.17; 'saying': 0.18; 'module': 0.19; 'import': 0.21; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'script': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'maybe': 0.29; 'file': 0.32; 'function.': 0.33; 'symbol': 0.33; 'another': 0.33; 'pm,': 0.35; 'there': 0.35; 'but': 0.36; 'subject:: ': 0.38; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'your': 0.60; 'letters': 0.62; 'strange': 0.62; 'more': 0.63; 'within': 0.64; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'special': 0.73; 'hundred': 0.95
Date Wed, 12 Dec 2012 12:53:27 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version 1.0
To Yong Hu <yhu221300@gmail.com>
Subject Re: How to import module whose filename starts number
References <39662302-5d9c-44fe-8ed2-e96bbca08714@googlegroups.com>
In-Reply-To <39662302-5d9c-44fe-8ed2-e96bbca08714@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:+EbQNQmoDX3Z2ElIJH/vEe06IeaAw18QVeLWyQJbvfL FLvkkd8g6EvyPrkz9meLIuj4/c2s0qGSMjM+Z+AqUiicvkR9/C oN1zrrNGOXIDpdYfYSPa1OFwTLGGQLxnEmtlb8pILpNxuRjJtE iz0RCTxWrdmCCEiWPFuES+s3MwmyzRvDNUGfIDQ7t5k63Zfh6n J3L9z3sRWuwTjqAX5yPQSUPNoUCt+KwGe2XiFZGKzpzwLIk86d lF5sIy5FVupFVVv9oW1bs2ugNMWO7Uqw3+sgRcv5Jc5fYUwC2o TaGSSNHg+JVCpO+G+IbPfhUfqtN8yfTXgxLZ2xPkXGsIWV2rQ= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
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.789.1355334831.29569.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355334831 news.xs4all.nl 6986 [2001:888:2000:d::a6]:53989
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34713

Show key headers only | View raw


On 12/12/2012 12:42 PM, 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?

A module name is like any other symbol in Python.  It must start with a
letter (one of a hundred thousand or so), and have only letters or
digits within it.  Plus underscore, and maybe a couple more special
characters.

mv would be your best bet.  But if you HAVE to have a strange name, try
using the __import__() function.



-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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