Parametrized module import
davidf at sjsoft.com
Fri Jul 9 12:09:31 CEST 2004
Jacek Generowicz wrote:
> I have a module whose behaviour needs to be configurable. The module
> needs to decide, the first time it is imported, beteween alternative
> interfaces it presents.
> Currently, I set some environment variables which select the desired
> behaviour, and the module inspects those variables to determine the
> mode in which it should set itself up. I would prefer a pure Python
> solution, rather than one which depends on external state.
> Can you recommend any approaches, or warn against the pitfalls of some
What I would recommend is class-ifying the code inside the module. Then
you can create a fresh object each time you want a different
configuration, and you don't have to worry about the relationship
between import and configure.
This may make your module more flexible as well
More information about the Python-list