将 python 参数传递给 shell

Pass python argument to shell

在 python 笔记本中,我想将第一行中的临时参数传递到最后一行,但我不知道该怎么做。

def grabdata(statefolders, temp, split_by):
    for folder in statefolders:
        sub = folder.split('_')[split_by]
        new_name = sub + '_out.txt'
        !cp {folder}/done/sigdet_output*out temp{new_name}

如果

!cp {folder}/done/sigdet_output*out temp{new_name}

是您通常在 shell 中执行的内容,Python 中的 command 将是:

import subprocess
subprocess.run(["cp", "{}/done/sigdet_output*out".format(folder), "temp{}".format(new_name)])