Я пытаюсь запустить свой test_script.py в main_script.py с помощью подпроцесса. test_script.py - это программа с несколькими суммами, а main_script.py должна вызывать ее с двумя аргументами и вывести вывод. Вот код:Результат проверки подпроцесса Python не работает
test_script.py
a = int(input())
b = int(input())
print(a+b)
main_script.py
import subprocess
subprocess.check_output(['python', 'test_script.py', 2,3])
Это им ошибка при получении:
Traceback (most recent call last):
File "C:/Users/John/Desktop/main_script.py", line 2, in <module>
subprocess.check_output(['python', 'test_script.py', 2,3])
File "C:\Python34\lib\subprocess.py", line 607, in check_output
with Popen(*popenargs, stdout=PIPE, **kwargs) as process:
File "C:\Python34\lib\subprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1085, in _execute_child
args = list2cmdline(args)
File "C:\Python34\lib\subprocess.py", line 663, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'int' is not iterable
http://stackoverflow.com/questions/14078117/how-do-you-use-subprocess-check-output-in-python – Tempux
ИМХО, это это плохая практика для вызова одного сценария из другого. Лучше просто «импортировать test_script» из 'main_script.py'. Или создайте функции/классы create в 'test_script' и вызовите их из' main_script.py', как 'test_script.my_function (2,3)' –