PEP 308: Pep Update
Andrew Dalke
adalke at mindspring.com
Thu Feb 13 13:40:09 EST 2003
Raymond Hettinger:
> The leading options on the table are:
>
> * (if <cond>: <expr1> else: >expr2>)
BTW, I never did see a response to this comment of mine. With the
above syntax, this means the following is legal
# get the 2-ple of name's value and who owns it
a = (
# The value can be cached or in the database
if is_cached:
self._get_cache[name]
else:
self.connection.fetch(name), # database already open when getting
source
# The ownership is stored in the database (if the
# name starts with "DB") or from the web service
if x.startswith("DB")
self.connection.get_owner(name)
else:
self.webservice.get_owner_by_name(name)
)
That is, code which in the small looks like normal Python if/else
statement is really an if/else expression once you look in the
larger scope, which may be indefinitely away. Also note that
the indentation level does not matter inside of the "a=(...)"
expression.
I don't like that. I would rather use two temporary names.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list