0

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}
1
  • Your last line would just cause a SyntaxError. Do you want to do something like subprocess.run('cp {folder}/done/sigdet_output*out {temp}{new_name}'.format(folder=folder, temp=temp, new_name=new_name), shell=True)? Commented Nov 11, 2016 at 15:38

1 Answer 1

1

If

!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
subprocess.run(["cp", "{}/done/sigdet_output*out".format(folder), "temp{}".format(new_name)])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.