Page 24 sur 28
External scripts
Import external scripts
Your working script needs to know where to find the external scripts:
sys.path.append('C:\\Users\\Georges\\PycharmProjects\\Your_Directory') from YourScriptWithoutExtension import SomeVariables, ...
But I think all your sub-script will be executed like that.
Include external Python code (without real importation)
Here, at the exec, your sub-script will be executed, and your main script will continue just after.
... YourFileCode = r'C:/Users/Georges/PycharmProjects/WorkEMC/YourFileCode.py' ... exec(compile(open(YourFileCode, 'rb').read(), YourFileCode, 'exec'))
Passing variables from one script to another without interference
Because just importing them, you will execute all scripts when you import.
So just use global variable, in your main script for example:
import os os.environ['MY_VARIABLE'] = str(my_variable)
Then use it in other scripts like that:
import os os.environ.get('MY_VARIABLE')