In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, Xiaobian will bring you an example analysis of the functions of the os library in python. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
OS libraries provide common, basic operating system interaction functions.
-OS library is Python standard library containing hundreds of functions
- Common path operations, process management, environmental parameters and other categories
- Path operation: os.path sub-library, processing file path and information
- Process management: Start other programs in the system
- Environmental parameters: obtain system software and hardware information and other environmental parameters
os.path sub-library takes path as the entry and is used to operate and process file paths.
import os.path
import os.path as op
os.path.abspath(path) #Returns the absolute path of path in the current system
os.path.normpath(path) #Normalized path representation, uniformly separated by\\path
os.path.relpath(path) #Returns the relative path between the current program and file
os.path.dirname(path) #Returns the directory name in path
os.path.basename(path) #Returns the last filename in the path
os.path.join(path, *paths) #Combines path and paths, returns a path string
os.path.exists(path) #Determine whether the file or directory corresponding to path exists, return True or False
os.path.isfile(path)
os.path.isdir(path)
os.path.getatime(path) #Returns the last access time of the file or directory corresponding to path
os.path.getmtime(path) #Returns the last modification time of the file or directory corresponding to path
os.path.getctime(path) #Returns the last modification time of the file or directory corresponding to path
os.path.getsize(path) #Returns the size of the file corresponding to path, in bytes
Python OS Library Process Management
Calling an external program using the current python program
os.system(command)
Execute command in the operating system
Returns the return value of the command program after execution
import os#os.system(command)os.system("C:\\Windows\\System32\\calc.exe")os.system("C:\\Windows\\System32\\mspaint.exe" \ D:\\PYECourse\\grwordcloud.png)
Python gets or changes system environment information
os.chdir(path) #Modify the path of the current program
os.getcwd() #Returns the current path of the program
os.getlogin() #Get the current system login user name
os.cpu_count() #Get the number of CPUs in the current system
The above is a small series for everyone to share the Python OS library function example analysis, if there is a similar doubt, may wish to refer to the above analysis to understand. If you want to know more about it, please pay attention to 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.