471,328 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,328 software developers and data experts.

Library package import question


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

class Bar()
class Hmm()
class Bee()
class Wax()
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

Thanks for input.
Nov 5 '07 #1
0 772

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by David M. Wilson | last post: by
7 posts views Thread by Kevin Newman | last post: by
5 posts views Thread by sophie_newbie | last post: by
reply views Thread by Roger Ineichen | last post: by
1 post views Thread by mypetslug | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.