Python popenIt is a method in the python OS module. It is very good to execute some system commands, and it can return something you want.
The specific explanation of the python popen is to open a command or a slave pipeline. The returned value is an open file object connected to the pipeline. The read/write mode is based on whether it is 'R' (preset) or 'W '. The bufsize argument is the same as the corresponding parameter Meanings of the built-in open () function. This command (waiting for the exit status of encoding in the specified format () is considered as the return value of the close () file object method, it is not returned unless the exit status is zero (no error is terminated. Availability: Unix operating system and windows.
Suppose we want to write information about all the files in the current path in Linux:
For I in OS. popen ('LS-al '):
Print I
The returned result is:
-RW ------- 1 WL wheel 73981952 1 11 2010 python. Core
-RW ------- 1 WL wheelel 69844992 12 12 2009 python2.5.core
Drwxr-XR-x 7 WL wheel 1024 11 27 2009 Release
-RW-r -- 1 WL wheel 17 1 8 2010 Renren. coockie
-RW-r -- 1 WL wheel 24936 11 1 2008 scrumper. py
...
Based on the above results, you can use OS. popen is used to execute some other system methods. My current working platform is on Unix. You can also see how to use Python popen on Windows to execute some system commands, I believe we can have different surprises.
OriginalArticlePlease indicate Reprinted from Old Wang python, this article address: http://www.cnpythoner.com/post/87.html
Author: Lao Wang @ Python tutorial
Old Wang Python provides Python-related Django tutorials and Python downloads!