检查Python脚本中存在的文件 作者: admin 时间: 22/11/05 13:00:24 分类: Python 是否有任何方法可以检查Python脚本中的文件是否存在。 # 回答1 导入os模块并使用os.path。isfile(path)函数 # 回答2 Python提供了exists()函数,可以如下使用。 选择 | 换行 | 行号 import os.path if(os.path.exists("/etc/passwd")): print("/etc/passwd exists") 标签: python