[Python-ideas] Improve circular import

Victor Varvariuc victor.varvariuc at gmail.com
Tue Apr 10 13:30:00 CEST 2012


On Tue, Apr 10, 2012 at 12:55 PM, Oleg Broytman <phd at phdru.name> wrote:

> Why does a submodule import the entire package instead of importing
just root?

import tree, sys
print("tree.branch: 'root' in dir(tree) ->", 'root' in dir(tree))
print("tree.branch: 'tree.root' in sys.modules ->", 'tree.root' in
sys.modules)

Ignore this part - my fault. It should have been:

import sys
print("tree.branch: 'root' in dir(main) ->", 'root' in
dir(sys.modules['__main__']))
print("tree.branch: 'tree.root' in sys.modules ->", 'tree.root' in
sys.modules)

This shows that `root` attribute does not exist yet in main, though
'tree.root' exists in `sys.modules`.
--
*Victor*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120410/b2805060/attachment.html>


More information about the Python-ideas mailing list