[Python-Dev] Syntax suggestion for imports
Tony Nelson
tonynelson at georgeanelson.com
Thu Jan 3 20:20:00 CET 2008
At 3:20 PM +0100 1/3/08, Christian Heimes wrote:
>Raymond Hettinger wrote:
>> How about a new, simpler syntax:
...
>> * import readline or emptymodule
>
>The syntax idea has a nice ring to it, except for the last idea. As
>others have already said, the name emptymodule is too magic.
>
>The readline example becomes more readable when you change the import to
>
>import readline or None as readline
>
>
>In my opinion the import or as syntax definition is easy to understand
>if you force the user to always have an "as" statement. The None name is
>optional but must be the last name:
>
>import name[, or name2[, or name3 ...] [, or None] as target
...
At 11:48 AM -0600 1/3/08, Ron Adam wrote:
...
>An alternative possibility might be, rather than "or", reuse "else" before
>import.
...
I prefer "else" to "or" but with the original single-statement syntax.
If the last clause could be an expression as well as a module name, what
I've done (used with and copied from BeautifulSoup):
try:
from htmlentitydefs import name2codepoint
except ImportError:
name2codepoint = {}
could become:
from htmlentitydefs else ({}) import name2codepoint as name2codepoint
Also:
import foo or (None) as foo
--
____________________________________________________________________
TonyN.:' <mailto:tonynelson at georgeanelson.com>
' <http://www.georgeanelson.com/>
More information about the Python-Dev
mailing list