from pathlib import Path
时间: 2024-01-22 16:19:40 浏览: 89
The `pathlib` module provides an object-oriented approach to handle file system paths and file operations. The `Path` class represents a path in the file system, and it provides various methods to manipulate paths and perform file operations.
Here is an example of how to import the `Path` class from the `pathlib` module:
```
from pathlib import Path
```
After importing the `Path` class, you can create a `Path` object to represent a file or directory on your file system. For example, to create a `Path` object for a file named `example.txt` in the current directory, you can do:
```
path = Path("example.txt")
```
You can then use various methods of the `Path` object to perform file operations, such as reading from or writing to the file, creating directories, or listing files in a directory.
阅读全文