Re: Parametrized module import

From: george young (gry_at_ll.mit.edu)
Date: 07/08/04


Date: Thu, 8 Jul 2004 10:01:21 -0400

On 08 Jul 2004 09:43:31 +0200
Jacek Generowicz <jacek.generowicz@cern.ch> threw this fish to the penguins:

> 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?

You might look at the way pygtk does it. I haven't peeked inside, but the
api is:

import pygtk
pygtk.require('2.0') # or '1.2' or some other version
import gtk # uses state set by require() to load the appropriate version

The pygtk.py file looks quite reusable with hardly any change...

See: http://www.pygtk.org

-- George

-- 
"Are the gods not just?"  "Oh no, child.
What would become of us if they were?" (CSL)


Relevant Pages

  • Parametrized module import
    ... I have a module whose behaviour needs to be configurable. ... needs to decide, the first time it is imported, beteween alternative ... interfaces it presents. ... I set some environment variables which select the desired ...
    (comp.lang.python)
  • Re: Batch file and MFC (Properly Terminating Application)
    ... This is not the first time it has happened. ... I enjoy tech support calls to people who never heard of environment variables, ... So you are declaring x but not y; then you're declaring x in the next line. ... what I want to know is what is purpose of function UINT ...
    (microsoft.public.vc.mfc)
  • Re: PERL 5.88 doesnt run on RH 8 gui... runs only on non-gui mode
    ... On Mon, 4 Aug 2003, Didier Casse wrote: ... It's the first time that I encounter such weird ... to recall that the path and other environment variables are set ...
    (RedHat)