【问题标题】:File tests in Python? [duplicate]在 Python 中进行文件测试? [复制]
【发布时间】:2014-02-15 18:09:45
【问题描述】:

我想使用 Python 3.3.3 来测试是否存在备份文件。

类似这样的:

if backup does not exist:
    create it
    write to backup

otherwise:
    run other procedures not related to backup file

有什么建议吗?

【问题讨论】:

标签: python


【解决方案1】:

使用os.path.existsos.path.isfile

>>> import os
>>> os.path.isfile('/path/to/file')
False

【讨论】:

  • 请在此处插入有关引入竞争条件等的常见警告...
【解决方案2】:

看看os.path.exists

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 2019-05-21
    • 2013-09-17
    • 1970-01-01
    相关资源
    最近更新 更多