code_junkie

Confusion about global variables in python

Nov 13th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. one.py:
  2. -------
  3.  
  4. def my_function():
  5. if _debug:
  6. print "debugging!"
  7.  
  8.  
  9. two.py:
  10. -------
  11.  
  12. from one import *
  13. _debug = False
  14.  
  15. my_function()
  16.  
  17. NameError: global name '_debug' is not defined
  18.  
  19. constants.py
  20. ------------
  21. debug = True
  22.  
  23. one.py
  24. ------
  25. from constants import debug
  26. #...
  27.  
  28. two.py
  29. ------
  30. from constants import debug
  31. #...
  32.  
  33. from one import *
Add Comment
Please, Sign In to add comment