Author r.david.murray
Recipients brett.cannon, dmugtasimov, docs@python, ncoghlan, r.david.murray
Date 2013-01-08.14:43:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> So it looks like if "import xyz.b" bahaves different depending on how 
> 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.
Date User Action Args
2013-01-08 14:43:17r.david.murraysetrecipients: + r.david.murray, brett.cannon, ncoghlan, docs@python, dmugtasimov
2013-01-08 14:43:17r.david.murraysetmessageid: <>
2013-01-08 14:43:17r.david.murraylinkissue16891 messages
2013-01-08 14:43:16r.david.murraycreate