Package importing problem

  • Thread starter =?iso-8859-9?Q?Tongu=E7?= Yumruk
  • Start date
?

=?iso-8859-9?Q?Tongu=E7?= Yumruk

Hi,

I'm writing a plugin based application with python 2.1 but I really have
some trouble with creating a package. My directory structure is:


Skib/Server/Python/:
skib
skibserver

Skib/Server/Python/skib:
__init__.py
PluginManager.py
plugins

Skib/Server/Python/skib/plugins:
default
__init__.py

Skib/Server/Python/skib/plugins/default:
default.py
__init__.py

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?

Thanks.

--
Love, Respect, Linux
############################################################################
Whom computers would destroy, they must first drive mad.
############################################################################
Tonguç Yumruk

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/WuAo1xWu4MLSyoYRAlh+AKCJSV5XTM9ek+E6CjIN1kJmRDDUXwCg3wGn
//5/Q80TfREQk9pjrRXBJes=
=iL4M
-----END PGP SIGNATURE-----
 
P

Peter Otten

Tonguç Yumruk said:
Hi,

I'm writing a plugin based application with python 2.1 but I really have
some trouble with creating a package. My directory structure is:


Skib/Server/Python/:
skib
skibserver

Skib/Server/Python/skib:
__init__.py
PluginManager.py
plugins

Skib/Server/Python/skib/plugins:
default
__init__.py

Skib/Server/Python/skib/plugins/default:
default.py
__init__.py

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?

Thanks.

I think that is because skib/PluginManager.py was never imported. Putting

import PluginManager

into skib/__init__.py should do (just a guess, though).

Peter
 
J

John J. Lee

Peter Otten said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top