[Python-Dev] Alternative imports (Re: Python 3 design principles)

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Sep 1 05:32:45 CEST 2005


Oren Tirosh wrote:
> Writing programs that run on both 2.x and 3 may require ugly
> version-dependent tricks like:
>> try:
> compile
> except NameError:
> from sys import compile

Just had a weird thought. What if you could write
 from sys or __builtin__ import compile
which would be equivalent to
 try:
 from sys import compile
 except ImportError:
 from __builtin__ import compile
Greg


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /