[docs] [issue16891] Fix docs about module search order
R. David Murray
report at bugs.python.org
Tue Jan 8 15:43:17 CET 2013
R. David Murray added the comment:
> So it looks like if "import xyz.b" bahaves different depending on how
> a.py was initially loaded as a script or imported from another module.
There are several differences between importing a module and running a script, one of which is what is on sys.path. You constructed your example to mask the path difference.
You are getting hit by the difference between absolute and relative imports. How implicit relative imports behave are one of the other things that are different between running a file as a script and importing it. This kind of confusion is one of the reasons implicit relative imports were dropped in Python3.
If you add
from __future__ import absolute_import
to the top of your a and t files, t will no longer produce an import error.
It could be that the documentation could be improved, but I'm not sure it is worth the effort for 2.7. If there are statements in the 3.x docs that are incorrect now that implicit relative imports are gone, those would definitely be worth fixing.
----------
nosy: +r.david.murray
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16891>
_______________________________________
More information about the docs
mailing list