I. Introduction
The following paths are for windows, and you will often see the following paths when you open a file in a py file you have written.
We often use '/' to indicate the relative path, '\' to indicate the absolute path, web page URLs and linux, unix systems generally use '/'
open('') open('/data/') open('D:\\user\\')
The first two are relative paths, the third is an absolute path. Absolute path is better understood, that is, the most complete path, relative path of the relative path is incomplete path, this relative refers to the relative to the current folder path
II. Absolute paths
1. The current situationfile (paper)The absolute path of the
path1=('.') print(path1)
Results for:
D:\babytree\MyTest\common
2. Indicates the current location of thefile (paper)The absolute path to the previous level folder:
path2=('..') print(path2)
Results for:
D:\babytree\MyTest
3.1 CurrentfileThe absolute path of :
path3=(__file__) print(path3)
Results for:
D:\babytree\MyTest\common\
3.2 CurrentfileThe absolute path of :
import sys print([0])
The output result is:
D:\babytree\MyTest\common\
III. Relative paths
'/' to represent relative paths, as shown (. represents the parent directory)
The current script is a file in the conmon folder, we need to find the location of the file. (Print the absolute path to the file)
print(("../config/"))
Results for:
D:\babytree\MyTest\config\
to this article on python read relative paths and absolute paths to this article, more related to python read relative paths and absolute paths to content please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!