Library package import question

Frank Aune Frank.Aune at broadpark.no
Mon Nov 5 14:34:26 CET 2007


Hello,

I have a python library package 'Foo', which contains alot of submodules:

Foo/:
	__init__.py
	module1.py:
		class Bar()
		class Hmm()
	module2.py
		class Bee()
		class Wax()
	module3.py
		etc etc

To prevent namespace pollution, I want to import and use this library in the 
following way:

import Foo
(...)
t = Foo.module2.Bee()

To accomplish this, I put explicit imports in __init__.py:

import module1
import module2
import module3

what Im wondering about, is if its a more refined way of doing this, as the 
explicit imports now need to be manually maintained if the library grows. 
I've tried to use __all__, but this only seems to work with "from Foo import 
*" and it causes modules to be imported directly into the namespace of 
course.

Thanks for input.
-Frank



More information about the Python-list mailing list