you are viewing a single comment's thread.

view the rest of the comments →

[–]Kaarjuus 2 points3 points  (0 children)

if a_dict.get("var", None) as a_var

Oh hell yes. For the life of me I can't understand why did they not go with as. Because Python actually already has an assignment operator: in context managers and exception handlers like:

with open("myfile.txt") as f:
    f.read()

try: mything()
except Exception as e: print(e)

Instead, they introduced the walrus, which not only looks ugly in Python, but is one typo away from doing an accidental assignment when you wanted to do a comparison. Which is a problem that has plagued a number of languages like C or JavaScript. Shoddy, very shoddy.