How to share globals between imported modules?
问题 I have two modules, a.py and b.py. I want the globals from a.py to be available in b.py like this: a.py: #!/usr/bin/env python var = "this is global" import b b.foo() b.py: #!/usr/bin/env python var = "this is global" def foo(): print var Currently, I re-declare the globals in each module. There must be an easier way. 回答1: Create a settings module that has shared globals if that's what you want. That way you're only importing and referencing each global one time, and you're keeping them