-
-
Save a-recknagel/1380a2576de27cb94a6cd88e799e748f to your computer and use it in GitHub Desktop.
assex leaking listcomp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> total = 0 | |
>>> [total := total + v for v in [1, 2, 3]] | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "<stdin>", line 1, in <listcomp> | |
UnboundLocalError: local variable 'total' referenced before assignment | |
>>> total # ?!?! | |
0 # D= | |
>>> [(total := total + v) for v in values] # parantheses don't solve the problem | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "<stdin>", line 1, in <listcomp> | |
UnboundLocalError: local variable 'total' referenced before assignment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment