Parametrized module import
David Fraser
davidf at sjsoft.com
Fri Jul 9 06:09:31 EDT 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
> approaches?
>
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
David
More information about the Python-list
mailing list