Advertisement
Guest User

python import statement bug

a guest
Oct 25th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # Test weird import bug
  4.  
  5. import logging
  6.  
  7.  
  8. config = {}
  9. config['log'] = {}
  10. config['log']['log_type'] = 'file'
  11. config['log']['log_file'] = './log'
  12. config['log']['config'] = { 'version' : 1 }
  13.  
  14.  
  15. def do_config_logging():
  16. if config['log']['log_type'] == 'from_config':
  17. import logging.config
  18. logging.config.dictConfig(config['log']['config'])
  19. elif config['log']['log_type'] == 'file':
  20. logging.basicConfig(filename=config['log']['log_file'])
  21. logging.info("start logging")
  22.  
  23.  
  24. if __name__ == "__main__":
  25. do_config_logging()
  26.  
  27.  
  28. Results in:
  29.  
  30. Traceback (most recent call last):
  31. File "./bug.py", line 25, in <module>
  32. do_config_logging()
  33. File "./bug.py", line 20, in do_config_logging
  34. logging.basicConfig(filename=config['log']['log_file'])
  35. UnboundLocalError: local variable 'logging' referenced before assignment
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement