开发者

Python calendar, counting empty days of the week before the first of the month

开发者 https://www.devze.com 2023-03-17 22:49 出处:网络
I did something like this : import datetime nb_blank_days = (int(datetime.date(year, month, 1).strftime(\'%w\'))+6)%7

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

精彩评论

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

关注公众号