issue on internal import in a package

Ben Finney ben+python at benfinney.id.au
Sun Feb 27 07:40:54 EST 2011


人言落日是天涯,望极天涯不见家 <kelvin.you at gmail.com> writes:

> Here is a simple example:
> [app]
>       [module]
>             __init__.py   --> empty
>             a.py   --> import b
>             b.py  --> defined a function foo()
>       test.py
>
> In the test.py, contains the below statement:
> from module import a
> Execute the test.py will get error:

This works fine for me::

    $ mkdir --parents app/module/
    $ touch app/module/__init__.py
    $ printf "import b\n" > app/module/a.py
    $ printf "def foo(): pass\n" > app/module/b.py
    $ printf "from module import a\n" > app/test.py
    $ find .
    .
    ./app
    ./app/module
    ./app/module/__init__.py
    ./app/module/a.py
    ./app/module/b.py
    ./app/test.py

    $ python app/test.py 

> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "module\a.py", line 1, in <module>
>     import b
> ImportError: No module named b
>
> Why the b.py can not be found by a.py?

I get no errors; the code appears to run fine. Perhaps the scenario is
not exactly as you describe?

-- 
 \       “If we listen only to those who are like us, we will squander |
  `\   the great opportunity before us: To live together peacefully in |
_o__)            a world of unresolved differences.” —David Weinberger |
Ben Finney



More information about the Python-list mailing list