The examples in this article describe how Python implements the processing pipeline. Share to everyone for your reference. The specific analysis is as follows:
What is the most dazzling magic that can be performed under Linux? Believe that different people say different, but if there is no pipe, then I am afraid that the magic will be lost magic
Here's how to use Python to handle these pipelines
Pipeline Call subroutine
We want to use a subroutine in the program, but need to dynamically pass the parameters (the dynamic in this case, refers to according to the second son program input results to determine what this input), how to do it, do not panic, there are subprocess!
Let me start with an example code and his output!
#!/usr/bin/pythonfrom subprocess Import *# subprocess Management, can do a lot of sub-process files, we want to introduce this file P = Popen (["Cat", "-N"], bufsize= 1024,stdin=pipe, Stdout=pipe, close_fds=true) # Open Program The first parameter is a list (program name, parameter) # The second parameter is the buffer size # Stdin,stdout is the setting whether to open these pipes, If his value is subprocess. Pipe, # will open, same as stdin and stderr# Close_fds set to True (unix-only) all file descriptors except (0,1,2) are closed before subroutine execution (FIN, fout) = (P.stdin, P.stdout) for I in Range (10): # You'll understand ^_^ fin.write ("line" + str (i)) fin.write (' \ n ') Fin.flush () Print Fout.readline ()
The result of his output is:
Line0line1line2line3line4line5line6line7line8line9
Hopefully this article will help you with Python programming.