Importing Version Specific Modules

Michael Crute mcrute at gmail.com
Fri Dec 5 01:46:06 CET 2008


On Thu, Dec 4, 2008 at 7:33 PM,  <skip at pobox.com> 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



More information about the Python-list mailing list