We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is it possible and if so, what is the proper way to create a global library?
If I have (my_lib.py):
foo = 1 def init(): global foo foo += 5 print foo # prints 6
And then in another file (main.py):
from my_lib import * if __name__ == "__main__": init() print foo # prints 1 instead of 6!!
It prints 1 because it refers to the foo created with the import. The one that is 6 refers to
This is because I use the
But without I have to use
my_lib. as a prefix all the time.
And I can do
import my_lib as l to shorten that prefix but I don't want that.
So is there any way to make things global without this annoying side effect?