如何打开我刚刚在上面几行python中创建的目录(使用当前日期和时间创建文件夹)



datestring=datetime.datetime.now((.strftime("%Y-%m-%d"(打印(日期字符串(os.mkdir(日期字符串(

(现在我需要打开这个文件夹并创建一个csv文件名作为考勤(

f=打开(日期字符串,'Attendance.csv','r+'(

writer=csv.writer(f(

最简单的方法是使用文件的相对路径。此外,我认为在操作文件时应该使用with语句。

datestring = datetime.datetime.now().strftime("%Y-%m-%d")
print(datestring)
os.mkdir(datestring)
with open(datestring + '/Attendance.csv', 'r+') as f:
writer = csv.writer(f)
# ... your further code ...

相关内容