James Hewitt <j...@caurinus.com> added the comment:
I don't quite follow... the 'import logging.config' statement should never be executed, and if it is commented out the program works fine as written. It's as if the mere presence of the statement in the code causes 'logging' to be shadowed inside the function. -James On 10/25/2018 12:58 PM, Steven D'Aprano wrote: > > Steven D'Aprano <steve+pyt...@pearwood.info> added the comment: > > This is expected behaviour: import is a form of assignment. > > "import logging", like "logging = 1", tells the compiler to treat logging as > a local variable (unless you declare logging as global). As the exception > says, you are trying to access the logging local variable before it has been > assigned to. > > You can (and should!) give a SHORT and SIMPLE demonstration, without any > excess and irrelevant code: > > py> def demo(): > ... if False: > ... import logging > ... logging > ... > py> demo() > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "<stdin>", line 4, in demo > UnboundLocalError: local variable 'logging' referenced before assignment > > So this is expected behaviour. > > ---------- > nosy: +steven.daprano > resolution: -> not a bug > stage: -> resolved > status: open -> closed > > _______________________________________ > Python tracker <rep...@bugs.python.org> > <https://bugs.python.org/issue35069> > _______________________________________ > ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35069> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com