Re: Importing Version Specific Modules
- From: "Michael Crute" <mcrute@xxxxxxxxx>
- Date: Thu, 4 Dec 2008 19:46:06 -0500
On Thu, Dec 4, 2008 at 7:33 PM, <skip@xxxxxxxxx> wrote:
Michael> try:
Michael> from string import Template
Michael> except ImportError:
Michael> from our.compat.string import Template
This is "easier to ask forgiveness than permission" (EAFP). This tends to
be more Pythonic (and thus, preferred). You don't *really* care what the
version just, but whether or not the string module has a Template object.
Besides, what if some bright admin at some customer decides to backport the
Template implementation to their 2.4 installation? The first form would
load your compatibility version, probably not what they were hoping when
they put in the effort to backport.
That was the kind of reasoning I'm looking for. I'll stick with the
pythonic try/except approach then.
-mike
--
________________________________
Michael E. Crute
http://mike.crute.org
God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
.
- Prev by Date: Re: RELEASED Python 3.0 final
- Next by Date: Re: Running Python 2 and Python 3 on the same machine
- Previous by thread: Re: Importing Version Specific Modules
- Next by thread: watch football online for free
- Index(es):
Relevant Pages
|