我正在尝试编写一个程序,它会给我一个很好的 .txt 文件来显示今年的日历,但是,我不想使用日历功能,而是使用datetime。
我希望它具有以下格式(我希望它旁边有一周中每一天的前 3 个字母):
周二 1 月 1 日
1月2日星期三
一直到
12月31日星期二
(基本上 365 行,每行 10 个字符,每行以换行符“\n”结尾)。这是我从各种堆栈流问题、教程和模块中收集到的。至今没有成功。
import datetime
from datetime import date
textfile = file('new_file.txt','wt')
your_date.isoformat()
your_date.strftime("%A %d. %B %Y")
My main issue is that I am unfamiliar with how I get python to give me a range of dates (here being the year 2013, but it could also be just any increment in time such as June 2011 to December 2014) and of course to print the day of the week next to it. This way it could be adapted to any time period you might need this small calendar for. I was thinking maybe assigning every day's number (1 being Monday, 2 being Tuesday is the pattern if I'm correct) the first 3 letters of a day in the week so it's all neat and of the same length.