There are several ways to achieve this, if you’re coding it yourself you’re already on the right path. It’s actually a much better idea to have the two experiments as separate files.
It will really be worth your while to make sure you have a good understanding of how functions work, of how to import code from another file, and maybe learn about how classes work. Once you understand these basic python and programming concepts, this should make a lot of sense. Take a few days and do some python tutorials on these topics (though classes might be a bit of a bigger topic that will take time to absorb).
To give a short answer, I would recommend writing a separate file that acts as your main script, and calls the other scripts. Here’s an example where the two entire experiments would each be wrapped in a function I’m calling “run”. Since we know functions can accept arguments, and then return values, you can save the values returned from the first experiment and pass them to the function that contains your second experiment. Here’s a very simple example with three files:
exp1.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
def run(arg1, arg2):
# experiment code written here
# note that indentation is very important
# in python
result1 = arg1 + arg2
return result1
exp2.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
def run(arg1, arg2, arg3):
# experiment code here
result2 = arg1 + arg2 + arg3
return result2
expController.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# Here we make the code from
# exp1.py and exp2.py available
import exp1
import exp2
if __name__ == '__main__':
arg1 = u"Hey "
arg2 = u"Steve."
# we call the function "run()" in exp1,
# and save its return value in a variable
# called result1, which we plan to hand to
# experiment 2
result1 = exp1.run(arg1, arg2)
arg3 = u" How're "
arg4 = u"you?"
# run experiment 2
result2 = exp2.run(result1, arg3, arg4)
print(result2)
You also need to add a file called __init__.py (that’s two underscores before and after init), in the same folder. This file can be blank, but it needs to exist. This tells python that code from this folder can be imported.
I recommend making these four files and putting them in a separate folder to test this concept out. For this example to work, exp1.py, exp2.py, expController.py and __init__.py all have to be in the same folder.
Then to run it, in the terminal / command line, make sure that you’re in the same folder as the as the script, and run:
python expController.py
This calls our main script, which will call the individual experiment scripts. In this example, it should print “Hey Steve. How’re you?” to the console. Hopefully this will get you started, and maybe someone else will chime in with different ideas, but I would stay away from a solution using execfile(), especially since you want to pass around arguments, and doing it this way will introduce you to some fundamental programming concepts.
And rereading your question, I would put the code for deciding which experiment to run in the expController.py.