Pathlib usage reference, pathlib reference

Source: Internet
Author: User

Pathlib usage reference, pathlib reference
If any error occurs, you must specify pathlib as path3.x. It has powerful functions and is easier to operate directories. For example, you can use this module to operate directories using python3.x.

Import pathlib ----> This is just a feature 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 part of the path1 and path2 Directories

2. glob and fnmatch

Glob is an attribute of pathlib. Path. After returning a generator loop, you can use stem (get file name), suffix (suffix, return string), and suffixes --> return list.

Fnmatch is a separate library used to filter keywords and return bool values.

3. New Features of pathlib File Reading 3.5.x

Pathlib. path ('filename'). read_text () can directly read the file.

Official documents: https://docs.python.org/3/library/pathlib.html? Highlight = read_text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.