Re: A decade or so of Python programming, and I've never thought to "for-elif"

2021-12-01 Thread Rob Cliffe via Python-list
If for ... else was spelt more intelligibly, e.g. for ... nobreak, there 
would be no temptation to use anything like `elif'. `nobreakif' wouldn't 
be a keyword.

Rob Cliffe

On 30/11/2021 06:24, Chris Angelico wrote:

for ns in namespaces:
 if name in ns:
 print("Found!")
 break
elif name.isupper():
 print("All-caps name that wasn't found")

This actually doesn't work. I have been programming in Python for well
over a decade, and never before been in a situation where this would
be useful.

As YAGNIs go, this is right up there.

(For the record, since this was the last thing in the function, I just
made the break a return. Alternatively, an extra indentation level
"else: if name.isupper():" wouldn't have been that terrible.)

Your random piece of amusement for today.

ChrisA


--
https://mail.python.org/mailman/listinfo/python-list


A decade or so of Python programming, and I've never thought to "for-elif"

2021-11-29 Thread Chris Angelico
for ns in namespaces:
if name in ns:
print("Found!")
break
elif name.isupper():
print("All-caps name that wasn't found")

This actually doesn't work. I have been programming in Python for well
over a decade, and never before been in a situation where this would
be useful.

As YAGNIs go, this is right up there.

(For the record, since this was the last thing in the function, I just
made the break a return. Alternatively, an extra indentation level
"else: if name.isupper():" wouldn't have been that terrible.)

Your random piece of amusement for today.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list