Conditional Import
Michael Hudson
mwh at python.net
Thu Mar 14 12:14:24 EST 2002
Danil <danil at ultranet.com> writes:
> Is there a standard python idiom for coping with importing one of several
> libraries?
>
> Right now, I've this hack in the middle of my code
>
> try:
> from codeop import CommandCompiler
> except:
make that
except ImportError:
> from MockCommandCompiler import CommandCompiler
>
> But if I have to put up with a work around like this, I'd prefer that it
> be fairly elegant. Or at least standard...
try:...except ImportError:...
is standard.
> p.s. because codeop.CommandCompiler fails in 2.1,
I know, I wrote it for 2.2... do the workarounds mentioned in the
docs:
http://www.python.org/doc/current/lib/module-codeop.html
help?
> and I've yet to find a recipe that will get me to Win32 + Python 2.2
> + pygtk. That help would be appreciated too; I've been unable to
> find or build a _gtk.pyd that python22 will import.
Can't help you here.
Cheers,
M.
--
(ps: don't feed the lawyers: they just lose their fear of humans)
-- Peter Wood, comp.lang.lisp
More information about the Python-list
mailing list