I would like to pass around a global variable in python. I know this is not an advisable method, but this belongs to a bigger application where I need to do this.
this is my main.py
from allfiles.subfiles.allclasses import Machine
global a
def func():
a=5
print("Inside function:", a)
func()
print("Outside function:", a)
machine = Machine(a)
and this is my allclasses.py
import main
class Machine():
def __init__(self, name):
print("created machine: ", main.a)
see attached picture of the structure...
somehow the import main in the allclasses is a problm. i tried from main import * same problem I have an import error: Cannot import name 'Machine' from 'allfiles.subfiles.allclasses
I just need to pass around this global variable from to allclasses (unidirectional so there will be no cyclic problems) the value is set once (from func) and won t be changed anymore Am I missing something basic here?