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

How does python judge the absolute path?

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the python how to judge the absolute path of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will get something after reading this python article on how to judge the absolute path, let's take a look.

Description

1. A path that begins with / has nothing to do with the current directory and is called an absolute path.

2. The absolute path is the path that starts at the top of the file system, always starting from the root folder. In the Window system, the drive letter (C:, D:) is used as the root folder.

Example

> import os > os.path.abspath ('regular Code practice strip.py')' D:\\ Python36\\ regular Code practice strip.py' > import os > os.path.abspath ('regular Code practice strip.py')' D:\\ Python36\\ regular Code practice strip.py' > os.path.abspath ('(read-write file) crazily fill in 2.py') # this file does not exist in the current directory \ Python36\ (read and write files) crazily fill in words 2.py' > > os.path.abspath (r'\ Python programming Quick start + + let tedious work from\ (read and write files) crazily fill in words 2.py') # this directory also does not exist in the current directory.'d:\\ Python programming Quick start + + let tedious work from\ (read and write files) crazily fill in words 2.py' > > os.path.abspath (r'\\) Desktop\ Python programming Quick start + + automate tedious work\ (read and write files) crazily fill in words 2.py') D:\\ Desktop\\ Python programming Quick start + + automate tedious work\ (read and write files) crazily fill in words 2.py' > os.path.abspath (r'\ Administrator\ Desktop\ Python programming Quick start + + automate tedious work\ (read and write files) crazily fill in words 2.py') D:\\ Administrator\\ Desktop\\ Python programming Quick start + + automate tedious work\ (read and write files) crazily fill in words 2.py' # if you don't specify the top root directory The top of the directory returned by this function is the top of the current directory That is, "D:\\" > > os.path.abspath (racy C:\ Users\ Administrator\ Desktop\ Python programming Quick start + + automate tedious work\ (read and write files) crazily fill in words 2.py')'C:\\ Users\\ Administrator\\ Desktop\\ Python programming Quick start + + automate tedious work\ (read and write files) crazily fill in lyrics 2.py' > > import os > os.path.relpath ('C:\\ Windows') 'C:\\') 'Windows' > os.path.relpath (' C:\\ Windows','C:\\ spam\\ eggs')..\\..\\ Windows' > os.getcwd () D:\ Python36' this is the end of the article on "how to determine an absolute path by python" Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to judge the absolute path of python". If you want to learn more knowledge, you are 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.

Share To

Development

Wechat

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

12
Report