In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what is the use of Popen class in python", the content is simple and clear, and I hope it can help you solve your doubts. Let me lead you to study and learn this article "what is the use of Popen class in python".
Popen class
Popen class of the subprocess module. This class can be used to replace the os.popen function. But the disadvantage of the Popen class is that it is a little more complicated to use because it is too powerful. For example:
Print (subprocess.Popen ("echo Hello World", shell=True, stdout=subprocess.PIPE) .stdout.read ()
This line of code can be used to replace the following code:
Print (os.popen ("echo Hello World") .read ())
A more complex example of the Popen class is as follows:
Import subprocess p = subprocess.Popen ('ls', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in p.stdout.readlines (): print (line.decode ("utf-8"). Strip () retval = p.wait ()
This code reads all the lines of the result returned by the ls command through the standard output readlines method and outputs these contents to Console. Finally, use the wait method to wait for the execution of the ls command, and finally end the program.
The advantage of the Popen class over the popen function is that it unifies all the options in the Popen class, rather than requiring four different popen functions to do the job.
The above is all the content of the article "what is the use of Popen classes in python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.