Parametrized module import

anton muhin antonmuhin at rambler.ru
Thu Jul 8 11:11:50 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?
> 

Following `explicit is better than implicit` I'd prefer to have a huge 
interface class or object that would be instantiated with parameters. 
Something like this:

from myModule import myModule

myModule.tweak(<blah>)

...

myModule.doSomething()

Of course, this solution might not fit your needs.

regards,
anton.



More information about the Python-list mailing list