在 Python 中,可以使用 os.path 模块中的 os.path.exists(path) 函数来判断某文件是否存在。示例代码如下:
importos
if os.path.exists('path/to/file'):
print('The file exists.')
else:
print('The file does not exist.')
如果文件存在,该函数会返回 True ,否则会返回 False。
也可以使用 os.path.isfile(path) 来判断是不是文件



被折叠的 条评论
为什么被折叠?



