On 1/2/20 12:55 PM, Andrew Barnert via Python-ideas wrote:
> On Jan 2, 2020, at 06:32, Random832 <[email protected]> wrote: >> Mainly, you had mentioned you felt like "if try" had a 'smell' to it >> but couldn't figure out what it is, and I was trying help identify >> that, and... well, after thinking about it more, I realized - "if >> try" may not have many uses, but "if not try" has a million: any code >> of the form >> >> try: >> x >> except: >> y >> >> where x is an expression could be written as >> >> if not try x: >> y >> >> And therein lies the problem - it's a construct for catching >> exceptions with no provision for declaring what kind of exception is >> caught. You may have only envisioned it for ValueError, but it'd be >> weird for something that *looks* so general to be limited in that >> way. [...] > But it looks like it isn’t good enough, and I don’t think there’s any > other combination of existing keywords that could spell “if this > works”. I’ll give it a little more thought, but it’s probably not > going to pan out. Oh well. What about "if except" (any time I can eliminate a "not," that's a good thing): if except x: y which could even leave room to specify which exception(s) is/are caught: if except ValueError: x: y except that the two colons on one line look a little odd in Python. _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/GDTHWKXXKMCI6HK2L44HDZFSICELS6IF/ Code of Conduct: http://python.org/psf/codeofconduct/
