replacing `else` with `then` in `for` and `try`

Ned Batchelder ned at nedbatchelder.com
Wed Nov 1 19:10:26 EDT 2017


On 11/1/17 5:29 PM, Chris Angelico wrote:
> On Thu, Nov 2, 2017 at 8:23 AM, Ned Batchelder <ned at nedbatchelder.com> wrote:
>> On 11/1/17 5:12 PM, Alexey Muranov wrote:
>>> Hello,
>>>
>>> what do you think about the idea of replacing "`else`" with "`then`" in
>>> the contexts of `for` and `try`?
>>>
>>> It seems clear that it should be rather "then" than "else." Compare also
>>> "try ... then ... finally" with "try ... else ... finally".
>>>
>>> Currently, with "else", it is almost impossible to guess the meaning
>>> without looking into the documentation.
>>>
>>> Off course, it should not be changed in Python 3, maybe in Python 4 or 5,
>>> but in Python 3 `then` could be an alias of `else` in these contexts.
>>>
>>> Alexey.
>>>
>> Apart from the questions of backward compatibility etc (Python is unlikely
>> to ever go through another shift like the 2/3 breakage), are you sure "then"
>> is what you mean?  This won't print "end":
>>
>>      for i in range(10):
>>          print(i)
>>      else:
>>          print(end)
> Well, it'll bomb with NameError when it tries to look up the *name*
> end. But it will run that line of code - if you quote it, it will
> work.
>
> ChrisA

Naturally, I messed up on both a shallow and deep level! :) Or should I 
say derp level... :)

--Ned.



More information about the Python-list mailing list