1

I'm running the following piece of code:

p = subprocess.getoutput("python ./file.py")

How do I ensure the python version used is python3?

Thanks!

1
  • you might want to change the code so that it runs on both: p=subprocess.check_output('python ./file.py < input.txt', shell=True) Commented Nov 22, 2015 at 22:34

2 Answers 2

1

Assuming your controlling script is running in python 3, and thus you are simply wanting to run a subprocess of an identical version of python, then try:

import sys
p = subprocess.getoutput("'{}' ./file.py < input.txt".format(sys.executable))
Sign up to request clarification or add additional context in comments.

Comments

0

The obvious way to ensure python 3.x is used is:

p = subprocess.getoutput("python3 ./file.py < input.txt")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.