[New-bugs-announce] [issue10043] UnboundLocalError with local variable set by setattr, caused by code run later

Steven Samuel Cole report at bugs.python.org
Thu Oct 7 12:13:50 CEST 2010


New submission from Steven Samuel Cole <steven.samuel.cole at gmail.com>:

inside a function, I create a local variable by using setattr with the current module as object, as in
  setattr(modules[__name__], 'name', 'value')

if I _later_ in the code set name to None, the attribute becomes unavailable even for code that is executed _before_ setting name to None.

please also see sample file.

----------
components: Interpreter Core
files: show_weird_behavior.py
messages: 118099
nosy: ssc
priority: normal
severity: normal
status: open
title: UnboundLocalError with local variable set by setattr, caused by code run later
type: behavior
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file19146/show_weird_behavior.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10043>
_______________________________________


More information about the New-bugs-announce mailing list