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 ssc
Recipients docs@python, eric.smith, ssc
Date 2010-10-07.13:03:49
SpamBayes Score 5.551115e-17
Marked as misclassified No
Message-id <1286456632.19.0.823797357358.issue10043@psf.upfronthosting.co.za>
In-reply-to
Content
thank you very much for the clarification.

i did indeed not come across the page you've linked to, mainly because i did not really know what to google for. actually, i do not recall ever looking into the python language reference in 6+ years of python coding.

googling for 'python UnboundLocalError setattr' returns this bug report as top result at the moment, as your link leads to more indepth information, the main objective of saving / alleviating others the research work seems achieved. i will nonetheless try to make time to get get my head around the python doc conventions and processes and submit a patch.

thanks for pointing out the difference between a local variable and one with module scope. however, it is not relevant for my situation: i have a long list of strings coming in (database column names, not under my influence) which i need to access _like_ a local variable. if you can think of a smarter approach to turn parameter strings into variables of whatever scope, i'm all ears, but i have a feeling that's actually what setattr(...) is meant for.
 
as a quick fix for the UnboundLocalError, sticking to working with module attributes worked for me. instead of changing the value of a dynamically created variable in the conventional way
  my_var = None
(which is where the error occurred in my code), it might help to use setattr(...) even if the variable name is known:
  setattr(modules[__name__], 'my_var', None)
History
Date User Action Args
2010-10-07 13:03:52sscsetrecipients: + ssc, eric.smith, docs@python
2010-10-07 13:03:52sscsetmessageid: <1286456632.19.0.823797357358.issue10043@psf.upfronthosting.co.za>
2010-10-07 13:03:50ssclinkissue10043 messages
2010-10-07 13:03:50ssccreate