我目前使用的代码是:
date = time.strftime("%d/%m/%y")
filename = ('attendence{}' + str(date) +'.txt')
f = open(filename, 'w+')
但是,我收到的错误是:
FileNotFoundError: [Errno 2] No such file or directory: 'attendence{}31/03/17.txt'
这个错误与我的代码的其他部分无关,因为这样可以工作
f = open('attendence{}.txt', 'w+')
我的最终目标是创建一个包含当前日期的新文件
问题在于日期格式:
你可以试试:
'attendence{}31/03/17.txt'
不仅仅是一个文件名,它是一个相对路径:'attendence{}31'
'03'
'17.txt'
李>Python抱怨文件夹
'attendence{}31/03'
不存在注意
{}
可能会混淆系统、某些程序或某些用户。如果花括号内没有任何信息,不妨将其删除相关问题 更多 >
编程相关推荐