0

I am trying to launch a python 2.7 script called pp.py from a Python 3.6 script.

I am working on Windows 7

This is the 2.7 script:

#! C:\Python27\python.exe

import sys

sys.stdout.write("Hello from version %s\n" % (sys.version,))

If I launch it from the cmd window, it will return that it is using the 2.7 version, but if I call it from the 3.6 script with this instruction:

exec(open("pp.py").read())

then it will answer that it is using Python 3.6

Any ideas?

1 Answer 1

0

Python exec executes a string of code in the current version. I think you'll have to run a new process using the python version you want. If you need to read return values, use the Pipes, as described here

Follow the step here, and you'll have a distinction between python 2 and 3 (or use aliases in linux).

Then, you can use the Process class to to run your script.

Sign up to request clarification or add additional context in comments.

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.