[New-bugs-announce] [issue4109] Wrong UnboundLocalError with += operator
report at bugs.python.org
Sun Oct 12 15:56:42 CEST 2008
New submission from Eric Atienza <eric at ericaro.net>:
the following code :
for i in range(n):
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<console>", line 6, in test
File "<console>", line 5, in sub
UnboundLocalError: local variable 'code' referenced before assignment
error came from the += operator.
Tested for code initialized to '', to 0
I guess it's the same for all inline operators.
I agree that global variables CANNOT be assigned, it's ok.
But += (and I guess *= etc) operators are not assignements, and are not
different from .append(), or .extend() methods.
I was expecting += to work the same as append() method
components: Interpreter Core
title: Wrong UnboundLocalError with += operator
versions: Python 2.5.3
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce