Re: Importing Version Specific Modules



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
.



Relevant Pages

  • Re: Eine Vorlage aus Access heraus öffnen
    ... Michael ... >> schaffe ich es aber nicht, die Tabelle unter Benutzung der Vorlage zu ... > auf dem Template erstellen. ... > Erstellt eine neue Arbeitsmappe, ...
    (microsoft.public.de.excel)
  • Re: serious word template issue in Word 2003
    ... confirm that patch KB887979 is the culprit. ... >> template's dialog box, I'm going to use that to enable a template ... >>> to see if they can provide a better way to fix this problem. ...
    (microsoft.public.office.developer.vba)
  • Re: Harshmans end Part one
    ... Now on any INDIVIDUAL lifeform, ... But if you wanted to make numerous programs, using one template, you ... Earlier in that thread the OP was Michael from 209.2.60.83 ... from Michael on Jan 9th from 209.2.60.95 aka PaeTec Communications, ...
    (talk.origins)
  • Re: Importing Version Specific Modules
    ... Michael> from string import Template ... Michael> from our.compat.string import Template ... versions of Python. ...
    (comp.lang.python)
  • User Defined Types
    ... I have a global template in the startup directory. ... the information is combined into one string using the ... I would like to use the Sdr type with the SaveUserInfo code. ...
    (microsoft.public.word.vba.general)