
On Tue, Apr 7, 2009 at 9:03 AM, spir <denis.spir@free.fr> wrote:
Hello,
What's the reason why name = value if condition is invalid? Meaning: there _must_ be an else clause.
[I imagine this has been discussed and refused consciously, but I couldn't find it in PEP308, nore in archives.]
It would be practicle in many situations, e.g. to give default values to parameters:
def writeFile(text, title, format=STANDARD, fileName=None): fileName = title+".py" if fileName is None ...
Denis
PS: Sure, one can write if condition: name = value but the rationale in favour of, or against, a one-liner shortcut is the same as for the ternary case (with else).
You do realize that "if condition: name = value" is a valid one-liner, right ? if/else on the other hand is a two-liner at least. George