1

I have problem such is I have to use two scripts, one which is compatible only with Python2.7 and second which is compatible only with Python3.

So my question is if it is possible in any way to do that? (not refactoring the code) I thought about using execfile() but it also use only one compiler.

2
  • 2
    Invoke different python interpreters to execute different scripts? Commented May 10, 2015 at 14:36
  • How are the scripts related? Commented May 10, 2015 at 15:01

1 Answer 1

1

From what you say, these scripts are independent - you can't share variables between 2.7 and 3. How do you communicate between them?

You could:

  • Convert the 2.7 script to 3, using the 2to3 script provided by Python3. So you don't have to refactor manually. This usually works quite well.

  • Run one script, and call the other script from there calling, for example, subprocess to execute the other using the correct interpreter. Something like (from the 2.7 script):

    subprocess.call(['python3', 'other_script.py']) // or result = subprocess.check_output(['python3', 'other_script.py']) // if you need the script's output

  • Write a small bash (or .bat) and call one and the other.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.