[Python-ideas] Allow 'import star' with namespaces

Brendan Moloney moloney at ohsu.edu
Fri May 6 22:50:14 CEST 2011


Ethan Furman [ethan at stoneleaf.us] wrote:

> I'm not catching the vision -- could you put together a short example
> that would illustrate?

The motivation is really just for interactive usage (much like the current from-import-star). 

If 'pkg' contains a number of sub-packages/modules that take a while to import, it makes sense to not automatically import them into the 'pkg' namespace (in the pkg.__init__ module). Putting the sub-package/module names into the __all__ list gives interactive users the ability to import everything in one go using from-import-star. Unfortunately the from-import-star usage pollutes the current namespace, and thus its use is discouraged. 

So really the vision is that developers can make their packages convenient for interactive use (by setting the __all__ attribute) without requiring users to use a discouraged language feature or making regular import of the package slow.

Brendan


More information about the Python-ideas mailing list