user5826447 user5826447 - 5 months ago 28
Python Question

Pass python argument to shell

In the python notebook I would like to pass the temp argument in the first line to the last line, but am not sure how to do that.

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}

is what you would usually execute in your shell, the command in Python would be:

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