0

In my main script, I import one of my own module which contains global variables. This main script execute another script with the function exec (exec(compile(open(Seq_1, "rb").read(), Seq_1, 'exec')) and this other script import the same module. So my question is: does these scripts have access to the same global variables (that means if I modify one global variable, the other script will be impacted) or not?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
AJT
  • 59
  • 5
  • Read https://stackoverflow.com/questions/1463306/how-does-exec-work-with-locals?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Mazdak May 25 '18 at 15:44

1 Answers1

0

Python will run your file when you first import it. On the second import python won't re-run the file.

In practice, python functions and variables directly on modules (not wrapped in classes) works like singletons.

This answer explains more about it. You can directly refer to the docs, also suggested on linked answer.

leoschet
  • 1,697
  • 17
  • 33