Python 今天获取的脚本';如果不获取并移动文件,则s文件是否存在

Python 今天获取的脚本';如果不获取并移动文件,则s文件是否存在,python,python-3.x,Python,Python 3.x,标题文件检查python脚本 在python中,我如何知道今天的文件是否存在于文件夹中,如果文件不存在,则获取昨天的文件您可以通过python的简单错误处理来实现这一点: try: open('directory/name_of_todays_file', 'r') print('todays file exists') except: open('directory/name_of_yesterdays_file', 'r') print('todays fil

标题文件检查python脚本
在python中,我如何知道今天的文件是否存在于文件夹中,如果文件不存在,则获取昨天的文件

您可以通过python的简单错误处理来实现这一点:

try:
    open('directory/name_of_todays_file', 'r')
    print('todays file exists')
except:
    open('directory/name_of_yesterdays_file', 'r')
    print('todays file does not exist')

由于不清楚你在问什么,你的问题的可能重复可能会被关闭。学习如何提出一个好问题。