workalendar.europe library:如何找到假期

时间:2015-11-20 01:16:54

标签: python python-2.7 python-3.x

我正在尝试将假日名称传递给workalendar.europe库中的日期,但我没有结果

form workalendar.europe import France
cal._holidays.get(datetime.date(2015, 1, 1))

1 个答案:

答案 0 :(得分:1)

使用workalendar.core.Calendar.holidays返回(date, holiday)对的列表:

>>> import datetime
>>> from workalendar.europe import France
>>> cal = France()
>>> d = datetime.date(2015, 1, 1)
>>> holiday_map = dict(cal.holidays(d.year))  # list -> dict
>>> holiday_map.get(d, '?')
'New year'