import

Georg Brandl g.brandl-nospam at gmx.net
Sun Aug 20 14:01:34 EDT 2006


01 wrote:
> Georg Brandl wrote:
>> figo_wei01 at 126.com wrote:
>> > bugnthecode 写道:
>> >
>> >> How are you trying to import it? Is it in the same directory as your
>> >> other script? If not is your python path set correctly?
>> >>
>> >> When importing a module that you have written you exlude the .py
>> >> extension. You should be using:
>> >> import hello
>> >>
>> >> Hope that helps,
>> >> Will
>> >
>> > i am on a windows platform. i have written scrip named 123.py.  it can
>> > be run. ok i save it to C:\Python24 ,exactly the same dir where python
>> > works.  but " import 123" doesnt work.
>>
>> You can't import modules whose names have non-identifier names with
>> plain "import". Or would you like "123" to refer to a module?
>>
>> If you have to do this (and I have a strong feeling that you haven't)
>> use the built-in function __import__().
>>
> you have to name your program with the name mymodule,or something like
> that when you use "import".  does python have a clear declaration on
> how to name a module?

A module name can be everything also usable as a Python identifier. This
means that it contains only letters, digits and underscores and doesn't
start with a digit.

Running a file as the main file, using "python 123.py" works because
Python then won't need to provide the file name as a name in the script.

Georg



More information about the Python-list mailing list