I can't help but wonder...
Config:
mathieu@mathieu-UX21E:~/$ python --version
Python 2.7.5+
Code:
import logging
logger = logging.getLogger('x')
def main():
print logger
logger = 2
if __name__ == "__main__":
main()
Output:
mathieu@mathieu-UX21E:~/$ python ./manager.py
Traceback (most recent call last):
File "./manager.py", line 9, in <module>
main()
File "./manager.py", line 5, in main
print logger
UnboundLocalError: local variable 'logger' referenced before assignment
Obviously, I would expect that print statement to access the globally-defined logger variable. Is there something I did not understand about the python variable scoping rules ?
Also, obviously, the logger = 2 statement should not do much. However, if I remove it, the undefined variable exception disapears.