New submission from Eric Atienza [EMAIL PROTECTED]:
the following code :
def test():
code=''
def sub(n):
for i in range(n):
code+=str(i)
sub(5)
sub(10)
return code
test()
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
messages: 74666
nosy: atienza
severity: normal
status: open
title: Wrong UnboundLocalError with += operator
type: behavior
versions: Python 2.5.3
___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4109
___
___
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com