PEP 308: Pep Update
James J. Besemer
jb at cascade-sys.com
Thu Feb 13 23:41:01 EST 2003
Andrew Dalke wrote:
> 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.
As pointed out, the required parentheses make it less of an issue.
Furthermore, (although I know you'll disagree) I'll point out that your
general complaint here also constitutes an argument for going with the
operator based alternative,
a ? b : c
as it couldn't possibly be confused with if/else statements.
> Also note that
> the indentation level does not matter inside of the "a=(...)"
> expression.
This has always been the case within expressions. I agree the insides of
multi-line expressions should usually be indented but here you have
discovered yet another of the thousands of ways Python code is subject to
"abuse" by naive or sinister coders.
> I don't like that. I would rather use two temporary names.
I respect your preference and I'm even willing to FIGHT for your right to
always have that choice.
I just wish you'd be willing to be more flexible about other people's opinion
about style.
Regards
--jb
--
James J. Besemer 503-280-0838 voice
2727 NE Skidmore St. 503-280-0375 fax
Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com
http://cascade-sys.com
More information about the Python-list
mailing list