A collection of articles, ideas, and rambling from a guy who wrote some software that one time.

Tuesday, December 13, 2005

Python Namespace Problem

This problem periodically comes up, and generally an unsatisfactory solution is proposed, the cure is worse than the disease, it's rejected, and we ignore the problem for another year.

The 1:1 correspondence of modules to files in Python is handy, but sometimes inconvenient. I would like to be able to write large, complex packages in Python but constrain the interface that they present, so that users only have to import one module in order to use them.

What is a good way to do this?

2 comments:

moshez said...

A top-level module which imports the package and exports the public interfaces?

ggheorghiu said...

The py library has a homegrown mechanism for exposing a namespace that is distributed among various modules. See http://codespeak.net/svn/py/dist/py/__init__.py

Grig