import

Anand anand.chittu at gmail.com
Wed Jul 5 22:21:34 EDT 2006


David Jackson wrote:

> Hi all,
>
> I'm a real beginner with python but have what I think is a simple question.
> I am writing some simple modules and would like to place them into a
> subdirectory.  But then I cannot seem to import them.  I have tried the
> following.
>
> I wrote a module called fibo.py with some definitions in it (one called
> fibo).  In the same directory, I wrote another file (test.py) and began with
> import fibo.  This worked fine and I was able to use the function fibo as
> fibo.fibo.  Then, I made a directory called test and placed the file fibo.py
> in this directory.  I also placed a blank file called _init_.py into this
> directory.  I went back to the original directory and tried to import
> test.fibo but this fails.  I get the following error message:
>
> Traceback (innermost last)
>   File "...test.py", line 1, in ?
>     import test.fibo
>   File "...test.py", line 1, in ?
>     import test.fibo
> ImportError: No module named fibo

python is trying to import fibo from test.py not test directory. since
you have both test.py and test directory, it is using the first one.
try to rename your directory name to something else and try. that
should work.

Also you should do 
   from test import fibo


Anand




More information about the Python-list mailing list