pathlib only appeared after version path3.x. It has more powerful functions and is easier to operate directories. If you use python3.x to operate directories, you can consider using this module first.
import pathlib ---- > Just a few functions used this time to facilitate memory
1. relative_to
Path1 = Path("/home/dante")
path2 = Path("/ home/dante/project/src")
path2.relative_to(path1) ----------> project/src Remove the same parts in the path1 and path2 directories
2. glob and fnmatch
Glob is an attribute of pathlib.Path. After returning a generator loop, you can return it through stem (get the file name), suffix (suffix, return a string), suffixes--> The list is list
fnmatch is a separate library that filters keywords and returns bool values
3. pathlib reads files 3.5.x new features
pathlib.path ('filename').read_text() can read the file directly
The above is the detailed content of Analyze the use of pathlib. For more information, please follow other related articles on the PHP Chinese website!