Without testing, I am sure it would be slower. I suppose it would be reasonable if exceptions are raised in multiple places and the exceptions were given meaningful names. Best wishes Rob Cliffe On 01/03/2022 17:22, om wrote:
How does `try/except` (with raise AppropriateException inside the block) compare to a len-1 loop?
Om
---- On Tue, 01 Mar 2022 10:04:31 -0600 *python-ideas@python.org * wrote ----
I have use cases for "do exactly once". Basically a sequence of actions which can be broken off (when something goes wrong and the whole process should be aborted, or when something succeeds and there is no need to try alternatives) at various points with `break`. Thus avoiding multiple if...then indentation levels. Of course it can be spelled as for _ in '1': for _ in ['once']: etc. etc., so this is only a cosmetic need. Best wishes Rob Cliffe
On 01/03/2022 15:19, Eric Fahlgren wrote:
As you probably suspect, yes, it comes up every couple of years. Here's one of the recent threads (there are more, just search for 'until' in the archives), that might give you some ideas for how this discussion will progress. :)
https://mail.python.org/archives/list/python-ideas@python.org/thread/EDNARFL... <https://mail.python.org/archives/list/python-ideas@python.org/thread/EDNARFL2RGOE53SLWPTD5ZLJQOYSVDCR>
On Tue, Mar 1, 2022 at 7:09 AM <lynneandallan@optusnet.com.au <mailto:lynneandallan@optusnet.com.au>> wrote:
Has anyone considered the idea of adding a "do at least once" loop to Python? This is frequently referred to as a do ... while or repeat ... until.
At the moment, it's a bit of a hack to achieve this in that we do a 'while True: ( do thing ; if cond: ( break ) )'. Since I don't know how to format these messages, I've used '{' for line-beak-and-indent, ')' for line-break-and-dedent, and ';' for line-break-keeping-same-indent-level.
My initial thoughts are that it would be reasonably easy to add a 'repeat: ( do thing ) until condition' which would far better specify intent of the loop (despite the possibility of break, while-true loops give no indication that it's not an infinite loop.
And using repeat...until will ensure whoever had to add the code to the Python interpreter wouldn't have any clashes with the current while loop.
Thoughts, anyone? Anyone? Bueller? :-) _______________________________________________ Python-ideas mailing list -- python-ideas@python.org <mailto:python-ideas@python.org> To unsubscribe send an email to python-ideas-leave@python.org <mailto:python-ideas-leave@python.org> https://mail.python.org/mailman3/lists/python-ideas.python.org/ <https://mail.python.org/mailman3/lists/python-ideas.python.org/> Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2PM6QE... <https://mail.python.org/archives/list/python-ideas@python.org/message/2PM6QEZJAPE3H72GA6TJJIWNBT3Y3WLN/> Code of Conduct: http://python.org/psf/codeofconduct/ <http://python.org/psf/codeofconduct/>
_______________________________________________ Python-ideas mailing list --python-ideas@python.org <mailto:python-ideas@python.org> To unsubscribe send an email topython-ideas-leave@python.org <mailto:python-ideas-leave@python.org> https://mail.python.org/mailman3/lists/python-ideas.python.org/ <https://mail.python.org/mailman3/lists/python-ideas.python.org/> Message archived athttps://mail.python.org/archives/list/python-ideas@python.org/message/BYNJ6C... <https://mail.python.org/archives/list/python-ideas@python.org/message/BYNJ6C45M2QW6BA7QILGWTYYCCGETKSV/> Code of Conduct:http://python.org/psf/codeofconduct/ <http://python.org/psf/codeofconduct/>
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/QAGHJP... Code of Conduct: http://python.org/psf/codeofconduct/
On Wed, 2 Mar 2022 at 17:08, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
On Wed, 2 Mar 2022 at 09:58, Rob Cliffe via Python-ideas <python-ideas@python.org> wrote:
Without testing, I am sure it would be slower.
Does that mean if you do test it, it'll be faster? :-)
Wait, the reason my code is slow is that I don't have unit tests? Huh. Maybe I should get onto that. ChrisA
participants (3)
-
Chris Angelico
-
Greg Ewing
-
Rob Cliffe