This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric
Recipients eric
Date 2008-10-12.13:56:40
SpamBayes Score 3.0564257e-10
Marked as misclassified No
Message-id <1223819802.24.0.226294192921.issue4109@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2008-10-12 13:56:42ericsetrecipients: + eric
2008-10-12 13:56:42ericsetmessageid: <1223819802.24.0.226294192921.issue4109@psf.upfronthosting.co.za>
2008-10-12 13:56:41ericlinkissue4109 messages
2008-10-12 13:56:40ericcreate