issue on internal import in a package

人言落日是天涯,望极天涯不见家 kelvin.you at gmail.com
Sun Feb 27 08:13:48 EST 2011


On Feb 27, 8:40 pm, Ben Finney <ben+pyt... at benfinney.id.au> wrote:
> 人言落日是天涯,望极天涯不见家 <kelvin.... 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

Thanks for your reply.
What's the version of your Python?  My version is 3.2.
Python 2.5/2.6 doesn't have this issue.



More information about the Python-list mailing list