code_junkie

Can someone explain __all__ in Python?

Nov 10th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. __all__ = ['bar', 'baz']
  2.  
  3. waz = 5
  4. bar = 10
  5. def baz(): return 'baz'
  6.  
  7. from foo import *
  8.  
  9. print bar
  10. print baz
  11.  
  12. # The following will trigger an exception, as "waz" is not exported by the module
  13. print waz
  14.  
  15. a = "A"
  16. b = "B"
  17. c = "C"
  18.  
  19. __all__ = ['a', 'b']
  20.  
  21. a = "A"
  22. b = "B"
  23. c = "C"
  24.  
  25. __all__
  26.  
  27. __all__
Add Comment
Please, Sign In to add comment