PEP308: Yet another syntax proposal
vze4rx4y at verizon.net
Mon Feb 10 18:35:01 CET 2003
"Aahz" <aahz at pythoncraft.com>
> I still have yet to see a clear explanation of why short-circuit is
> necessary and therefore iif() unreasonable.
It is necessary when:
1. One of the alternatives has a side-effect; or
2. one or both alternatives are time consuming; or
3. the validity of the alternatives depends on the outcome
of the test.
# Example where all three reasons apply
data = isinstance(source, str) ?? source.readlines() || source.split()
1. readlines() moves the file pointer
2. for long sources, both alternatives take time
3. split() is only valid for strings and readlines() is only
valid for file objects.
More information about the Python-list