[Python-Dev] intra-package mutual imports fail: "from <pkg> import <mod>"

Gordon McMillan gmcm@hypernet.com
Mon, 3 Jun 2002 08:37:10 -0400


On 2 Jun 2002 at 9:25, Guido van Rossum wrote:

[Matthias Urlichs]
> > The problem is that importing with from consists of
> > two steps: - load the module - add the imported names
> > to the local namespace
> 
> Good explanation!  This means it's an unavoidable
> problem.  

Um, different problem. What Matthias explains is
unavoidable. But in David's case, the containing
namespace (the package) is not empty when 
module2 wants module1.  In fact, I believe that
sys.modules['package.module1'] is there (though
*it* is empty).

My guess is that import is looking for module1
as an attribute of package, and that that binding
hasn't taken place yet.

If I use iu instead of the builtin import, it works.

-- Gordon
http://www.mcmillan-inc.com/