user5826447 user5826447 - 1 year ago 106
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}

Answer Source


!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)])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download