2016-11-11 7 views
0

pythonノートブックでは、最初の行のtemp引数を最後の行に渡したいのですが、それをどうするかわかりません。シェルへのPython引数の受け渡し

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

あなたは通常、あなたのシェルで実行されるものである

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} 
+0

あなたの最後の行には、単に '' 'SyntaxError'引き起こします''。 あなたは '' 'subprocess.run( 'cp {folder}/done/sigdet_output * out {temp} {new_name}')のようなことをしますか?format(folder = folder、temp = temp、new_name = new_name)、shell = True) '' '? –

答えて

1

場合は、Pythonでcommand次のようになります。

import subprocess 
subprocess.run(["cp", "{}/done/sigdet_output*out".format(folder), "temp{}".format(new_name)]) 
関連する問題