import os
year=2020
for month in range(1,13):
filename='{}.{}'.format(year,month)
os.mkdir(filename)
print(filename+'file created.')
程序会在你当前的工作目录生成日期文件夹。
程序还有些毛病,如果文件名已经存在,则会报错(Exception has occurred: FileExistsError),可以在os.mkdir(filename)前加个if语句进行判断,然后生成。
注意:你直接复制程序到ide执行可能会报错,因为其中的空格为不换行空格,在python中被视为语法错误。参考:https://blog.csdn.net/amber_o0k/article/details/104440719