need design suggestions: local namespace problem

John Roth johnroth at
Wed Oct 3 05:48:33 CEST 2001

"Jason R. Mastaler" <jason-dated-1002752519.c418b3 at> wrote in
message news:mailman.1002061380.5695.python-list at
> I'm looking for some design suggestions for how I might implement the
> following in Python.
> I'm writing a mail application that needs to have different values for
> variables depending on whether the app is running under qmail or
> Sendmail.
> Currently I have those variables in a module called "".
> So, within the program main, I do things like:
>   import Defaults
>   sys.exit(Defaults.ERR_HARD)
> Some of these variables need to conditionally have different values as
> I mentioned.  For example, exit status codes.  Under qmail,
> `ERR_HARD = 100', while under Sendmail, `ERR_HARD = 75'.
> I was thinking of splitting up into multiple files
> ( and, and then using local namespace trickery so
> that within the program main I can do things like:
>   if qmail:
>      import Qmail as mta
>   elif sendmail:
>      import Sendmail as mta
>   sys.exit(mta.ERR_HARD)
> However, the "import module as name" syntax is a Python2-ism, and I'd
> still like to support Python-1.5.2 if I can.
> Any design suggestions for how I might do this another way?
> Thanks.

Wrap the whole thing in a proxy class. Then  you just import the
proper module, and away you go. If you want to add another
mail program later, you just have to add an appropriate proxy
with the same interface.

That's what classes are for - hiding the implementation.

John Roth

More information about the Python-list mailing list