python - Best way to pipe output of Linux sort -


i process file line line. need sort first piping:

sort --key=1,2 data |./script.py.   

what's best call sort within python? searching online see subprocess or sh module might possibilities? don't want read file memory , sort in python data big.

its easy. use subprocess.popen run sort , read stdout data.

import subprocess myfile = 'data' sort = subprocess.popen(['sort', '--key=1,2', myfile],     stdout=subprocess.pipe) line in sort.stdout:     your_code_here sort.wait() assert sort.returncode == 0, 'sort failed' 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -