Message74666
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 |
|
Date |
User |
Action |
Args |
2008-10-12 13:56:42 | eric | set | recipients:
+ eric |
2008-10-12 13:56:42 | eric | set | messageid: <1223819802.24.0.226294192921.issue4109@psf.upfronthosting.co.za> |
2008-10-12 13:56:41 | eric | link | issue4109 messages |
2008-10-12 13:56:40 | eric | create | |
|