I have my Python code to run a simulation stored in a file called script
. This script takes a lot of input parameters that will be used to run the simulation. Now, I want to separate the definitions of these input parameters from the actual code that does the simulation because I might want to run many simulations with different sets of inputs (corresponding to different physical situations, for example). And the file where these inputs are defined will in general not be in the same folder as script
, but I will 'feed' this input to the script from the command line in this way: script input.py
(there is this line: /path/to/python python
at the top of script
). The style the inputs are defined inside input.py
is nothing fancy, it is all that any Python interpreter understands, e.g. var = value
if its a scalar parameter, or var = [value1, value2, value3]
if it's a list, etc. So, what I want is basically to copy-paste the content of input.py
to script
before running script
. I think I can achieve this by using
import sys
inp_file = str(sys.argv[1])
exec("import %s" % inp_file)
inside script
, but I would need to add the path where input.py
is to the PYTHONPATH
variable before running script
. Is there a way to do it without having to do anything with environment variable?