for -- else: what was the motivation?

avi.e.gross at gmail.com avi.e.gross at gmail.com
Sat Oct 15 18:50:14 EDT 2022


This has been discussed so often precisely because I swear NO CHOICE of keyword would satisfy everybody! Most languages start with designated keywords and some reserve a few for later use. But then things can get frozen in place to avoid breaking existing programs or break older compilers/interpreters.

Some languages use techniques to extend themselves more harmlessly such as creating a singleton object that has content that can be regular data as in math.pi, or functions/methods or new ides like "Symbols" that allow all kinds of extensions to the language in a fairly harmless way as no older program would likely have used features that did not exist.

That might not easily solve this problem. But I wonder if reserving some kind of prefix might help, so anything like extension.0nNoBreak could be added to a loop as a final clause and be treated as a non-key keyword of sorts.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com at python.org> On Behalf Of Rob Cliffe via Python-list
Sent: Wednesday, October 12, 2022 6:20 PM
To: python-list at python.org
Subject: Re: for -- else: what was the motivation?

I too have occasionally used for ... else.  It does have its uses. But oh, how I wish it had been called something else more meaningful, whether 'nobreak' or whatever.  It used to really confuse me.  Now I've learned to mentally replace "else" by "if nobreak", it confuses me a bit less.
Rob Cliffe

On 12/10/2022 22:11, Weatherby,Gerard wrote:
> As did I.
>
> tree = ET.parse(lfile)
>              for child in tree.getroot():
>                  if child.tag == 'server':
>                      break
>              else:
>                  raise ValueError(f"server tag not found in {lfile}")
>
> I think there are other places I could be using it, but honestly I tend to forget it’s available.
>
> From: Python-list <python-list-bounces+gweatherby=uchc.edu at python.org> 
> on behalf of Stefan Ram <ram at zedat.fu-berlin.de>
> Date: Wednesday, October 12, 2022 at 2:22 PM
> To: python-list at python.org <python-list at python.org>
> Subject: Re: for -- else: what was the motivation?
> *** Attention: This is an external email. Use caution responding, 
> opening attachments or clicking on links. ***
>
> Axy <axy at declassed.art> writes:
>> So, seriously, why they needed else if the following pieces produce 
>> same result? Does anyone know or remember their motivation?
>    Just wrote code wherein I used "else"! This:
>
> import locale
> for name in( 'de', 'de_DE', 'deu_deu', 'deu', 'German', 'Deutsch' ):
>      try: locale.setlocale( locale.LC_ALL, name ); break
>      except locale.Error: pass
> else: print( "Programm kann deutsche Schreibweise nicht einrichten." )
>
>    .
>
>
> --
> https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/p
> ython-list__;!!Cn_UX_p3!iyDac-XjNlj78G0XwNzZ-FEHyuCZIy33n3cI9MUDM_FnEd
> R04mSQ5Ln0OA1ETUNloyH24iY9meNHVdixLgWRYL8$<https://urldefense.com/v3/_
> _https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iyDa
> c-XjNlj78G0XwNzZ-FEHyuCZIy33n3cI9MUDM_FnEdR04mSQ5Ln0OA1ETUNloyH24iY9me
> NHVdixLgWRYL8$>

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



More information about the Python-list mailing list