Python calendar, counting empty days of the week before the first of the month
I did something like this :
import datetime
nb_blank_days = (int(datetime.date(year, month, 1).strftime('%w'))+6)%7
But I doesn't looks very pythonic. Any help ?
The goal is to say that because the first of July is 开发者_JS百科a friday, there is 4 blanks in the week before displaying the first.
How about just
datetime.date(year, month, 1).weekday()
Since 0
is Monday, I think this does what you want.
精彩评论