我正在尝试从主脚本调用一个Python脚本,需要在主脚本中生成一次数据帧,然后将其作为参数传递给子进程脚本,并在子进程中使用它。以下是我撰写的所需Python主脚本。
from subprocess import PIPE, Popen
import pandas as pd
test_dataframe = pd.read_excel(r'C:\test_location\file.xlsx',sheetname='Table')
sp = Popen(["python.exe",'C:/capture/test.py'], shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
sp.communicate(test_dataframe)
下面是错误信息:
TypeError: 参数1必须可转换为缓冲区,而不是DataFrame
这是我第一次尝试使用subprocess模块,所以我还不是很熟练。任何帮助将不胜感激。
sp.communicate
返回的。此外,检查一下shell=True
的作用。你正在将命令作为数组传递,但也指定了shell=True
。 - Alexey Guseynov