osp.basename
时间: 2023-12-20 21:04:59 浏览: 232
os.name list
os.path.basename() is a method in Python's os.path module that returns the base name of a file or directory path. It extracts the last component of the path and returns it as a string. For example, if the path is "/home/user/Documents/file.txt", the basename() method will return "file.txt".
Syntax: os.path.basename(path)
Parameters:
- path: The file or directory path whose base name is to be extracted.
Return Value: A string representing the base name of the path.
Example:
```
import os
path = "/home/user/Documents/file.txt"
basename = os.path.basename(path)
print(basename) # Output: file.txt
```
阅读全文