温馨提示×

python怎么判断路径存不存在

小亿
88
2023-12-13 22:58:25
栏目: 编程语言

可以使用os.path.exists()函数来判断路径是否存在。该函数返回一个布尔值,如果路径存在则返回True,否则返回False。

示例代码:

import os

path = "/path/to/file"

if os.path.exists(path):
    print("路径存在")
else:
    print("路径不存在")

0