What is the best way to call a script from another script?
The usual way to do this is something like the following.
test1.py
def some_func(): print 'in test 1, unproductive'if __name__ == '__main__': # test1.py executed as script # do something some_func()
service.py
import test1def service_func(): print 'service func'if __name__ == '__main__': # service.py executed as script # do something service_func() test1.some_func()
This is possible in Python 2 using
execfile("test2.py")
See the documentation for the handling of namespaces, if important in your case.
In Python 3, this is possible using (thanks to @fantastory)
exec(open("test2.py").read())
However, you should consider using a different approach; your idea (from what I can see) doesn't look very clean.