开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜