0

I have 2 python programs running - parent program and child program. In my system I have 2 python versions running - 2.7 and 3.3. Sometimes I will use 2.7 to run the program and sometimes I will use 3.3. I will use the following command to run

./parent.py (default python27)
python33 parent.py

How could the parent program call the child run the child program, with the parent's python version?

Thanks in advance

3
  • 1
    That doesn't make much sense. You would have to be very careful to write a program (or two programs) that would run on both Python 2 and Python 3, as Python 3 made backwards-incompatible changes. Commented May 27, 2013 at 3:07
  • Actually my code can support both python27 and python33, as I just use some basic function. Since I need to test the compatibility of the whole system I need to run both program under python27 and python33. Therefore I have this issue which the child running same version as parent. Commented May 27, 2013 at 3:20
  • @BrenBarn: using the same source for both Python 2 and Python 3 is a valid choice even non-trivial codebases such as django do it. Commented May 27, 2013 at 4:32

1 Answer 1

2

While your example was poor, I think what you are after is sys.executable.

subprocess.call([sys.executable, "manage.py", "celeryd"])
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot. sys.executable is what I need. Thanks
it is unclear why do you use the string formatting here. If exe is intended as an argument for subprocess functions; a list [sys.executable, "manage.py", "celeryd"] is more portable and safer choice.
Hey J.F. You are are right - I was simply trying to give an example. I updated it to reflect a more clear example.

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.