[Python-3000] Changing the import machinery

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Apr 21 11:16:27 CEST 2006


Ian Bicking wrote:

> try:
>      from string import Template
> except ImportError:
>      from mypackage.backports.string24 import Template
> 
> Doing this in a more elegent or formalized fashion might be nice. 

Have you seen my proposal for "or" in import statements?
Would you consider that elegant enough?

> Versioning the standard library

My thought on versioning is that it should look something
like

   import spam[3:], movies.grail[2:4]
      # version 3 or later of spam, version 2, 3 or 4 of movies.grail

I would like this much better than some kind of require()
function. Integrating the version specification with the
import would solve some problems, such as the one mentioned
earlier where a tentative import fails when it would have
succeeded if some later require() had been done first.

The form that the version numbers should take is up to
debate, but I'd tend to keep it extremely simple, i.e.
just integers. The baroque possibilities offered by the
setuptools require() seem like overkill to me.

--
Greg


More information about the Python-3000 mailing list