Question: 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

[![structure](https://i.stack.imgur.com/QdVp7.png)](https://i.stack.imgur.com/QdVp7.png)

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?

Answer: 
This still does not solve my problem. the import is done after the definition of the variable. it follows the direction perfectly

```
   def func():
       global a
       a=5
       print("Inside function:", a)

    from allfiles.subfiles.allclasses import Machine

    func()

    print("Outside function:", a)

    machine = Machine()

```
You can't import two files to each other, I think you should use a database.