Similar questions have been asked before:
here, here and here, and I am aware of these.
Say you have 2 modules where one has global variables that you want to read from in another module. Is there a way to make these accessible across modules without having to refer to them as module.variable each time?
Example:
modulea.py:
import moduleb
from moduleb import *
print("A String: " + astring)
print("Module B: " + moduleb.astring)
afunction()
print("A String: " + astring)
print("Module B: " + moduleb.astring)
moduleb.py:
astring = "dlroW olleH"
def afunction():
global astring
astring = "Hello World"
The output is
A String: dlroW olleH
Module B: dlroW olleH
A String: dlroW olleH
Module B: Hello World
suggesting that by using "from module import * " the global variables are copied rather than referenced.
Thanks in advance for any help.