[Python-Dev] Syntax suggestion for imports

John Barham jbarham at gmail.com
Thu Jan 3 02:59:19 CET 2008


Raymond Hettinger wrote:

> How about a new, simpler syntax:
>
> * import threading or dummy_threading as threading
> * import xml.etree.CElementTree or cElementTree or elementree.ElementTree as ET
> * from cStringIO or StringIO import StringIO

These all look good to me.  The "short circuit" import syntax and
semantics are compact and intuitive.

> * import readline or emptymodule

This I find more problematic as "emptymodule" seems too magical.  Even
now any code that wants to use a module that might not have been
successfully imported needs to check if that's the case.  E.g., a
fuller current use-case would be:

try:
   readline = None
   import readline
except ImportError:
   pass

if readline is not None:
   readline.foo()
   ...

Conceivably emptymodule could act as a Null object but that could
create more problems than it solves.

  John


More information about the Python-Dev mailing list