Get the App
SLTechnology News&Howtos  ›  Development  › 

How does python judge the absolute path?

Shulou Source: shulou.com Published: 2022-05-31 17:43:51 10月05日 Update

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.

Tags: File madness path tedious work programming directory automation code regular top practice knowledge content folder article system value function instance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux MariaDB NVidia Shulou Technology