python如何判断指定路径是否存在
可以使用os.path.exists函数来判断指定路径是否存在。该函数会返回一个布尔值,如果路径存在则返回True,不存在则返回False。
示例代码如下:
import os
path = '/path/to/directory'
if os.path.exists(path):
print("指定路径存在")
else:
print("指定路径不存在")
在上述示例代码中,'/path/to/directory'为指定的路径,可以根据需要替换成实际的路径。根据os.path.exists函数的返回结果,打印出相应的提示信息。
原文地址: https://www.cveoy.top/t/topic/iGbQ 著作权归作者所有。请勿转载和采集!