I have two scripts: script1.py
and script2.py
script1 has its environment (say, python 2), and script2 has its own environment (say, python 3).
How can I make script 1 invoke script 2, with its corresponding environment?
Thanks
A workaround I can think of right now is os.system
used to execute other files.
example:
#!/usr/bin/env python3
import os
os.system("script2.py")
and
#!/usr/bin/env python2
print "script 2 running..."
print "script 2 running..."
is great example since python2.X
uses print
without parentheses and python3.X
uses print()
with parentheses
It's important to take note of the shebangs (#!/usr/bin/env python3
and #!/usr/bin/env python2
) on both scripts which point to the correct entepreters/env for both scripts
os.system
can also be used with arguments, like os.system("script2.py data.txt")
, which is great if you want to run another script with arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With