5 ms·
I'm stoked about the walrus operator. Ever since I heard it was being added I've grumbled when writing code that would have been clearer with it. Of course I h
by kbd 7y ago
I'm stoked about the walrus operator. Ever since I heard it was being added I've grumbled when writing code that would have been clearer with it.
Of course I have to ask, what was your preferred syntax?
- mkl 7y agoNot OP, but maybe it's "as": if re.match(pattern, string) as m: #use m Seems a bit more Pythonic, as "as" is already used like this with "with". Either one would be fine with me and useful.
- metalliqaz 7y agoyep, that's the one!
- TremendousJudge 7y agoIt's already used in imports as well! It was the better choice, I don't know which arguments convinced them otherwise
- kbd 7y agoI think I remember seeing something about the "as" syntax. Wish I could find what I read, IIRC some arguments convinced me that the walrus operator was an improvement.
- metalliqaz 7y agoit is discussed in the PEP https://www.python.org/dev/peps/pep-0572/#alternative-spellings https://www.python.org/dev/peps/pep-0572/#alternative-spelli...
- mixmastamyk 7y agoUnfortunately, none of the reasons listed against are very accurate.
- mixmastamyk 7y agoThe arguments were based around also supporting complex multiple assignments and being to be able to do them anywhere, not just if… and while…, list-comps, etc. Of course neither of those things have been seen in the wild or production code since. Some folks complain even the simple case above is less readable. "as" was the Pythonic choice, rather than the C/Pascalic one.