Hi,
I have a python script, which is executing again 4-5 python scripts. For performance reasons i want to use same interpreter for executing all the script.
Is it Possible to do that, if yes please help me out.
Thanks
Kamal
Hi,
I have a python script, which is executing again 4-5 python scripts. For performance reasons i want to use same interpreter for executing all the script.
Is it Possible to do that, if yes please help me out.
Thanks
Kamal
The currently executing interpreter is available in sys.executable. You can just pass that explicitly to subprocess.Popen as the first argument, or pass it as the 'executable' argument.
The obvious solution (which may require a little tweaking) is to just call the main function of each script from a master script. E.g., if script1.py contains:
#!/usr/bin/python
def main():
// Do something
if __name__ == "__main__":
main()
put in master.py
#!/usr/bin/python
import script1
def main():
script1.main()
if __name__ == "__main__":
main()
You can continue this pattern for as many scripts as you want.
Maybe you're looking for the execfile function in Python 2.x.
In Python 3 it was removed, but there are simple alternatives.