Changing Module Variables After Import
SO pyton gurus! I've just found an astonishing phenomenon that I don't understand. The problem can be best shown as code: #== kid.py ==# import dad def spam (): dad.spam() #
Solution 1:
- Because loading dad.py as the
__main__
module is independent of importing dad.py as thedad
module. - See my answer to 1.
- Import
__main__
instead if you must. But in general, don't try this. Find another way to accomplish your tasks (e.g. classes).
Printing __name__
at the top of dad.py will illustrate this.
Post a Comment for "Changing Module Variables After Import"