In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, Xiaobian will bring you about how to understand python os and os.path modules. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
python27
OS module
① Directory related
os.getcwd(): Get the current working directory
os.listdir ('/tmp'): Get files and directories in/tmp directory, list type
os.chdir ('/tmp'): Switch working directory to/tmp
os.mkdir ('/tmp'): Create/tmp directory
os.makedirs ('/a/b/c'): Create/a/b/c directory
os.rmdir ('/tmp'): Delete/tmp directory
os.removedirs ('/tmp'): recursively delete empty directories under/tmp
② Document related
os.remove ('a.txt '): remove a.txt
os.rename ('a.txt ','b.txt'): rename a.txt to b.txt
③ User related
os.getuid()
os.getgid()
os.getlogin()
os.path module (processing of paths)
os.path.abspath('. '): Gets the absolute path to the current file or directory, string type
os.path.basename ('/tmp/a.txt '): Returns a.txt string type
os.path.dirname ('/tmp/a.txt '): Returns/tmp string type
os.path.exists ('/tmp'): determines whether a file or directory exists
os.path.split ('/tmp/a.txt '): Returns a tuple containing dirname and basename, this example returns ('/tmp','a.txt' )
os.path. split text ('/tmp/a.txt '): Returns a tuple containing the file name and file extension, this example returns ('/tmp/a','.txt' )
os.path.join ('/tmp','a.txt'): join directories and files or join directories and directories, this example returns '/tmp/a.txt'
os.path.isabs(xxx): Determine if xxx is an absolute path
os.path.isdir(xxx): Determine if xxx is a directory
os.path.isfile(xxx): Determine if xxx is a file
os.path.islink(xxx): Determine if xxx is a link
os.path. samplefile (a,b): Determine whether a b is the same file
os.path.normpath ('/tmp/a//b/'): canonical path form, this example returns/tmp/a/b
os.path.walk ('/tmp'): Recursive tree directory
os.path.getatime(): Get file or directory access time
os.path.getmtime(): Get file or directory modify time
os.path.getctime(): Get file or directory change time
os.path.getsize(): Gets the size of a file or directory
ps: os and os.path are extremely frequent modules used when dealing with file system-related tasks, and should be kept in mind that multiple uses
The above is how to understand python os and os.path module shared by Xiaobian for everyone. If you happen to have similar doubts, you may wish to refer to the above analysis for understanding. 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.