Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic os operations of python3?

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "what are the basic os operations of python3". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the basic os operations of python3?"

Import os

# get the current working directory

Print (os.getcwd ())

# # switching directories

# os.chdir ("E:\ python_learn\ python")

# print (os.getcwd ())

# # current directory

# print (os.curdir)

# print (os.getcwd ())

#

# # superior directory

# print (os.pardir)

# print (os.getcwd ())

# # Recursive creation of multi-level directories

# os.makedirs (r "E:\ python_learn\ python\ day12\ a\ b")

# create a single-level directory, not a multi-level directory

# os.mkdir ("E:\ python_learn\ python\ day12\ a\ b")

# os.mkdir (r "E:\ python_learn\ python\ day12\ a")

Os.mkdir (r "E:\ python_learn\ python\ day12\ a\ b")

# # if the directory is empty, delete it; recursively to the directory at the next level, if empty, delete, and so on

# os.removedirs (r "E:\ python_learn\ python\ day12\ a\ b")

# Delete a single directory. If the directory is empty, delete it

Os.rmdir (r "E:\ python_learn\ python\ day12\ a\ b")

# list all files and directories in a directory

Print (os.listdir (r "E:\ python_learn\ python\ day12"))

# Delete a file

# os.remove ("E:\ python_learn\ python\ day12\ a\ test1.py")

# rename

# os.rename ("E:\ python_learn\ python\ day12\\ a\ test.py", "E:\ python_learn\ python\ day12\\ a\ test1.py")

# get file information

Print (os.stat ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# get file size

Print (os.path.getsize ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# Delimiter of the current platform

Print (os.sep)

# Line Terminator used by the current platform

Print (os.linesep)

# string used to split the file path

Print (os.pathsep)

# the platform currently in use, such as nt for win

Print (os.name)

# Environment variables

# print (os.environ)

# print (os.system ('dir'))

# absolute path

Print (os.path.abspath (_ _ file__))

# cut path into directory and file name tuples and return

Print (os.path.split ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# return to the catalogue which gynecology hospital in Zhengzhou has a good http://mobile.120zzzy.com/

Print (os.path.dirname ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# return file name

Print (os.path.basename ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# determine whether the path exists, and return True or False

Print (os.path.exists ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# determine whether it is an absolute path

Print (os.path.isabs ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# whether it is a file

Print (os.path.isfile ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# whether it is a directory

Print (os.path.isdir ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# get the last access time of a file or directory

Print (os.path.getatime ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# creation time of the output file

Print (os.path.getctime ("E:\ python_learn\ python\ day12\ a\ test1.py"))

# get the last modification time

Print (os.path.getmtime ("E:\ python_learn\ python\ day12\ a\ test1.py"))

At this point, I believe you have a deeper understanding of "what are the basic os operations of python3?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report