In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Operation: import module subprocess import subprocesszhi = subprocess.getoutput ('ls ')1. Common functions in the subprocess module Function descriptions subprocess.run() Functions new in Python 3.5. Executes the specified command, waits for the command to complete, and returns an instance of the CompletedProcess class containing the execution result. subprocess.call () Executes the specified command and returns the status of the command execution, similar to os.system(cmd). subprocess.check_call() Functions new in Python 2.5. Executes the specified command, returns status code if execution succeeds, otherwise throws exception. This is functionally equivalent to subprocess.run(..., check=True)。subprocess.check_output() Functions new in Python 2.7. Executes the specified command. If the execution status code is 0, the command execution result is returned. Otherwise, an exception is thrown. subprocess.getoutput(cmd) receives a command in string format, executes the command and returns the execution result, similar to os.popen(cmd).read() and commands.getoutput(cmd). subprocess.getstatusoutput(cmd) Executes the cmd command and returns a tuple (command execution status, command execution result output), similar in function to commands.getstatusoutput().
Description:
In Python versions after 3.5, the official documentation advocates using the functionality of the subprocess module through the subprocess.run() function instead of other functions; in Python versions before 3.5, we can use the functionality of the subprocess module through subprocess.call(), subprocess.getoutput(), and other functions listed above; subprocess.run(), subprocess.call(), subprocess.check_call(), and subprocess.check_output() are all high-level functions implemented by wrapping subprocess.Popen, so if we need more complex functionality, we can do it with subprocess.Popen. The subprocess.getoutput() and subprocess.getstatusoutput() functions are two legacy functions from Python 2.x's commands module. They implicitly invoke the system shell and do not guarantee the security and exception handling consistency that other functions have. Also, they only support Windows platforms starting with Python 3.3.4. Common functions and usages in python: input() print() max() min() float() string list() tuple() str() string int() integer set() set {'a': 1} dictionary (key: value) key must be unique! Six data types: list, dictionary, set are variable data types, tuple string is immutable. range() Usage: for i in range(1,10)/(1,10,2), followed by 2 for step import os,join Import a module, or import another.py file
sort();sorted() Usage:
Sorting a list using sort() modifies the list itself and does not return a new list, which is usually not as convenient as sorted(), but is more efficient if you do not need to keep the original list.
The reverse parameter of sorted() accepts False or True to indicate whether the order is reversed
sa = [3,5,1,8,2] sa.sort()print(sa) The output is: [1, 2, 3, 5, 8]sorted() Usage: my_list = [3, 5, 1, 8, 2]result = sorted(my_list)print result Reverse Usage: sa = [3,5,1,8,2,]aaa = sorted(sa,reverse=True) Output:[8,5,3,2,1]print(aaa)
Split()
.split() specifies a splitter such as: ('-') Common usage: sa ='a-b--c'print(sa)sss = list(sa.split ('-'))print(sss) Results before and after segmentation: a-b--c['a',' b','c']
The return value return xx is usually used in functions.
You can set it at will, you can return a variable value, you can also return the name of another function, such as: def cpu(): val4 = os.popen("w |awk 'NR==1{print $8,$9,$10}'") sui = val4.read() print ('cpu load: 1 minute, 5 minutes, 15 minutes respectively: ',sui) return sui
f.open('/root/test.html')
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.