Calling Python 2 script from Python 3

前端 未结 7 2139
青春惊慌失措
青春惊慌失措 2020-12-01 02:00

I have two scripts, the main is in Python 3, and the second one is written in Python 2 (it also uses a Python 2 library).

There is one method in the Python 2 script

7条回答
  •  庸人自扰
    2020-12-01 02:43

    It works for me if I call the python 2 executable directly from a python 3 environment.

    python2_command = 'C:\Python27\python.exe python2_script.py arg1'
    process = subprocess.Popen(python2_command.split(), stdout=subprocess.PIPE)
    output, error = process.communicate()
    
    python3_command = 'python python3_script.py arg1'
    process = subprocess.Popen(python3_command.split(), stdout=subprocess.PIPE)
    output, error = process.communicate()
    

提交回复
热议问题