当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python calendar yeardays2calendar()用法及代码示例


日历模块允许输出类似于程序的日历,并提供与日历相关的其他有用函数。 “日历”模块中定义的函数和类使用理想化的日历,当前的公历日历在两个方向上都无限期扩展。

Python中的yeardays2calendar()方法用于获取指定年份的数据。周列表中的条目是天数和工作日数的元组。这个月以外的天数为零。

用法: yeardays2calendar(year, width)

参数: 
year: year of the calendar
width: [Default:3] number of months in each row. 

返回: tuples of day numbers and weekday numbers.

代码1:


# Python program to demonstrate working 
# of yeardays2calendar() method 
  
# importing calendar module 
import calendar 
  
obj = calendar.Calendar() 
  
year = 2016
# default value of width is 3 
  
# priting with yeardays2calendar 
print(obj.yeardays2calendar(year))

输出:

[[[[(0, 0), (0, 1), (0, 2), (0, 3), (1, 4), (2, 5), (3, 6)], [(4, 0), (5, 1), (6, 2), (7, 3), (8, 4), (9, 5), (10, 6)], [(11, 0), (12, 1), (13, 2), (14, 3), (15, 4), (16, 5), (17, 6)], [(18, 0), (19, 1), (20, 2), (21, 3), (22, 4), (23, 5), (24, 6)], [(25, 0), (26, 1), (27, 2), (28, 3), (29, 4), (30, 5), (31, 6)]]

[[(0, 0), (0, 1), (0, 2), (1, 3), (2, 4), (3, 5), (4, 6)], [(5, 0), (6, 1), (7, 2), (8, 3), (9, 4), (10, 5), (11, 6)], [(12, 0), (13, 1), (14, 2), (15, 3), (16, 4), (17, 5), (18, 6)], [(19, 0), (20, 1), (21, 2), (22, 3), (23, 4), (24, 5), (25, 6)], [(26, 0), (27, 1), (28, 2), (29, 3), (30, 4), (31, 5), (0, 6)]]]]

代码2:迭代星期列表

# Python program to demonstrate working 
# of yeardays2calendar() method 
  
# importing calendar module 
import calendar 
  
obj = calendar.Calendar() 
  
# iteratign with yeardays2calendar 
for day in obj.yeardays2calendar(2018, 1):
    print(day)

输出:

[[[(1, 0), (2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 6)], [(8, 0), (9, 1), (10, 2), (11, 3), (12, 4), (13, 5), (14, 6)], [(15, 0), (16, 1), (17, 2), (18, 3), (19, 4), (20, 5), (21, 6)], [(22, 0), (23, 1), (24, 2), (25, 3), (26, 4), (27, 5), (28, 6)], [(29, 0), (30, 1), (31, 2), (0, 3), (0, 4), (0, 5), (0, 6)]]]

[[[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 5), (2, 6)], [(3, 0), (4, 1), (5, 2), (6, 3), (7, 4), (8, 5), (9, 6)], [(10, 0), (11, 1), (12, 2), (13, 3), (14, 4), (15, 5), (16, 6)], [(17, 0), (18, 1), (19, 2), (20, 3), (21, 4), (22, 5), (23, 6)], [(24, 0), (25, 1), (26, 2), (27, 3), (28, 4), (29, 5), (30, 6)], [(31, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6)]]]



相关用法


注:本文由纯净天空筛选整理自Shivam_k大神的英文原创作品 Python calendar module | yeardays2calendar() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。