Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Test weird import bug
- import logging
- config = {}
- config['log'] = {}
- config['log']['log_type'] = 'file'
- config['log']['log_file'] = './log'
- config['log']['config'] = { 'version' : 1 }
- def do_config_logging():
- if config['log']['log_type'] == 'from_config':
- import logging.config
- logging.config.dictConfig(config['log']['config'])
- elif config['log']['log_type'] == 'file':
- logging.basicConfig(filename=config['log']['log_file'])
- logging.info("start logging")
- if __name__ == "__main__":
- do_config_logging()
- Results in:
- Traceback (most recent call last):
- File "./bug.py", line 25, in <module>
- do_config_logging()
- File "./bug.py", line 20, in do_config_logging
- logging.basicConfig(filename=config['log']['log_file'])
- UnboundLocalError: local variable 'logging' referenced before assignment
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement