Library package import question

F

Frank Aune

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
 

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,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top