Package importing problem

John J. Lee jjl at pobox.com
Sun Sep 7 19:09:37 EDT 2003


Peter Otten <__peter__ at web.de> writes:

> Tonguç Yumruk wrote:
[...]
> > in all the __init__.py files I have the __all__=["blah","blah"]
> > statement. When I try it as:
> > 
> > from skib import PluginManager
> > PluginManager.init_plugins()
> > 
> > It works. But when I try it like that:
> > 
> > import skib
> > skib.PluginManager.init_plugins()
> > 
> > It raises AttributeError and complains that there is nothing called
> > PluginManager. Subpackages also behave like that. The __init__.py files
> > only contain the __all__ directive. No actual code are in them. Am I
> > missing a point?
[...]
> I think that is because skib/PluginManager.py was never imported. Putting
> 
> import PluginManager 
> 
> into skib/__init__.py should do (just a guess, though). 

Right (though I should warn I didn't actually read your directory
structure, Tongu).  An __init__.py is required for packages, and in
order to import stuff from the package, you have to import that stuff
into __init__.

__all__ is just for

from skib import *


which you almost certainly don't (or shouldn't) want anyway.


John




More information about the Python-list mailing list