How to redirect output with subprocess in Python?

后端 未结 5 1622
孤街浪徒
孤街浪徒 2020-11-22 07:41

What I do in the command line:

cat file1 file2 file3 > myfile

What I want to do with python:

import subprocess, shlex
my         


        
5条回答
  •  误落风尘
    2020-11-22 08:11

    One interesting case would be to update a file by appending similar file to it. Then one would not have to create a new file in the process. It is particularly useful in the case where a large file need to be appended. Here is one possibility using teminal command line directly from python.

    import subprocess32 as sub
    
    with open("A.csv","a") as f:
        f.flush()
        sub.Popen(["cat","temp.csv"],stdout=f)
    

提交回复
热议问题