
On Mon, Jan 17, 2022 at 7:36 AM John Sturdy <jcg.sturdy@gmail.com> wrote:
For example, it bugs me that you can write:
if a: b = f(x) else: b = g(y)
and get the same variable 'b' from it in the lines of code following that, regardless of which path was taken.
Really? But that is a VERY common pattern. In fact, I would find it very hard to write an enormous amount of code without it. and what if you refactored that to be: b = f(x) if a else g(x) Do you really want that to mean something different ?!?! Or are what you are getting at that if you want those two forms to be the same, then you'd need to do something like: b = None if a: b = f(x) else: b = g(y) Which means essentially that you'd like to have to declare names in order to ues them outside the very narrowest of scopes. But this is not how Python works, and it never has, it would be a really massive change, and I for one, would not like it :-( Also -- which blocks would create a new scope? All of them: for (else) while (else) with if (elif, else) try (except, else) I guess what I'm getting at is that I'm pretty sure I would find this useful rarely, and an annoyance often. - CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython