Could execfile
be what you're after? execfile('script2.py')
will work as if you had copied and pasted the entire contents of script2.py
into the console.
e.g. suppose script2.py
has:
def myFunction(a, b):
return a + b
and then in script.py
I could do:
# reads in the function myFunction from script2.py
execfile('script2.py')
myFunction(1, 2)
If you want to execute script2.py
with parameters passed in from script.py
then I suggest that the contents of script2.py
are encased in a function. That is, if your script2.py
is:
a = 1
b = 2
result = a + b
I'd suggest you convert it into:
def myFunction(a, b):
return a + b
so that you can specify a
and b
from script.py
.