[Python-ideas] class ModuleNotFoundError(ImportError)

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Mar 1 01:07:36 CET 2011


Nick Coghlan wrote:

> Perhaps it it worth revisiting the old "import x or y or z as
> whatever" syntax proposal for 3.3

+1, as the suggested idiom is getting rather long-winded. Also
it gets worse when there are more than two alternatives, since
you end up with another nesting level for each fallback.

> (although deciding what, if anything to do for "from" style
> imports is a hassle)

I don't think it would be too bad:

    from x or y or z import foo, spam, eggs

This would first try to find one of the listed modules, and
having found it, import it and attempt to bind the specified
names.

Failures during the binding phase should probably *not*
trigger a fallback to the next module, to avoid ending up
with a situation where some of the names are imported from
one module and some from another. Since the internals of
the modules are probably incompatible with each other,
that would be a bad thing.

-- 
Greg

> 
> Cheers,
> Nick.
> 




More information about the Python-ideas mailing list