最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python標(biāo)準(zhǔn)庫(kù)calendar的使用方法

 更新時(shí)間:2021年11月23日 11:33:36   作者:玉米叢里吃過(guò)虧  
本文主要介紹了Python標(biāo)準(zhǔn)庫(kù)calendar的使用方法,calendar模塊主要由Calendar類與一些模塊方法構(gòu)成,Calendar類又衍生了一些子孫類來(lái)幫助我們實(shí)現(xiàn)一些特殊的功能,感興趣的可以了解一下

?此模塊允許你輸出類似Unix cal程序的日歷,并提供與日歷相關(guān)的其他有用功能。值得注意的是,默認(rèn)情況下,這些日歷將星期一作為一周的第一天,將星期日作為一周的最后一天(歐洲慣例)。不過(guò),我們可以使用setfirstweekday()方法來(lái)設(shè)置一周的第一天為星期日或h者其他工作日,指定的日期以整數(shù)形式給出。

calendar模塊主要由Calendar類與一些模塊方法構(gòu)成,Calendar類又衍生了一些子孫類來(lái)幫助我們實(shí)現(xiàn)一些特殊的功能

Calendar

模塊方法

setfirstweekday(firstweekday):指定一周的第一天,0是星期一,…,6為星期日

import calendar

# 將星期日設(shè)置為一周第一天
calendar.setfirstweekday(firstweekday=6)

firstweekday():返回一周的第一天,0是星期一,…,6為星期日

import calendar

# 將星期日設(shè)置為一周第一天
calendar.setfirstweekday(firstweekday=6)
print(calendar.firstweekday())      # 6

isleap(year):判斷指定是否是閏年,閏年為True,平年為False

import calendar

# 2018年是平年,所以為False
print(calendar.isleap(2018))        # False
# 2008年是如年,所以為True
print(calendar.isleap(2008))        # True

leapdays(y1, y2):返回y1與y2年份之間的閏年數(shù)量,y1與y2皆為年份。包括起始年,不包括結(jié)束年:

import calendar

# 2008到2011之間只有2008年是閏年,所以數(shù)量為1
print(calendar.leapdays(2008, 2011))    # 1

weekday(year, month, day):獲取指定日期為星期幾

import calendar

# 2018-08-08正是星期三,千萬(wàn)別忘記2代表的是星期三
print(calendar.weekday(2018, 8, 8))     # 2

weekheader(n):返回包含星期的英文縮寫(xiě),n表示英文縮寫(xiě)所占的寬度

import calendar

print(calendar.weekheader(4))

############### 打印結(jié)果如下 ###############
Mon  Tue  Wed  Thu  Fri  Sat  Sun 

monthrange(year, month):返回一個(gè)由一個(gè)月第一個(gè)天的星期與當(dāng)前月的天數(shù)組成的元組

import calendar

# 查看日歷可以知道,08-01正是星期三,并且8月共31天
print(2018, 8)      # (2, 31)

monthcalendar(year, month):返回一個(gè)月中天數(shù)列表(不是當(dāng)前月份的天數(shù)為0),按周劃分,為一個(gè)二維數(shù)組。包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

import calendar

calendar.setfirstweekday(firstweekday=6)
print(calendar.monthcalendar(2018, 8))

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

prmonth(theyear, themonth, w=0, l=0):打印一個(gè)月的日歷,theyear指定年份,themonth指定月份,w每個(gè)單元格寬度,默認(rèn)0,內(nèi)部已做處理,最小寬度為2,l每列換l行,默認(rèn)為0,內(nèi)部已做處理,至少換行1行

import calendar

calendar.setfirstweekday(firstweekday=6)
calendar.prmonth(2018, 8)

############### 打印結(jié)果如下 ###############
    August 2018
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

month(theyear, themonth, w=0, l=0):返回一個(gè)月的日歷的多行文本字符串。theyear指定年份,themonth指定月份,w每個(gè)單元格寬度,默認(rèn)0,內(nèi)部已做處理,最小寬度為2,l每列換l行,默認(rèn)為0,內(nèi)部已做處理,至少換行1行

import calendar

calendar.setfirstweekday(firstweekday=6)
print(calendar.month(2018, 8))

############### 打印結(jié)果如下 ###############
    August 2018
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

prcal(year, w=0, l=0, c=6, m=3):打印一年的日歷,w每個(gè)單元格寬度,默認(rèn)0,內(nèi)部已做處理,最小寬度為2,l每列換l行,默認(rèn)為0,內(nèi)部已做處理,至少換行1行,c表示月與月之間的間隔寬度,默認(rèn)為6,內(nèi)部已做處理,最小寬度為2,m表示將12個(gè)月分為m列

import calendar

calendar.setfirstweekday(firstweekday=6)
calendar.prcal(2018, m=4)

############### 打印結(jié)果如下 ###############
                                               2018

      January                   February                   March                     April
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6                   1  2  3                   1  2  3       1  2  3  4  5  6  7
 7  8  9 10 11 12 13       4  5  6  7  8  9 10       4  5  6  7  8  9 10       8  9 10 11 12 13 14
14 15 16 17 18 19 20      11 12 13 14 15 16 17      11 12 13 14 15 16 17      15 16 17 18 19 20 21
21 22 23 24 25 26 27      18 19 20 21 22 23 24      18 19 20 21 22 23 24      22 23 24 25 26 27 28
28 29 30 31               25 26 27 28               25 26 27 28 29 30 31      29 30

        May                       June                      July                     August
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
       1  2  3  4  5                      1  2       1  2  3  4  5  6  7                1  2  3  4
 6  7  8  9 10 11 12       3  4  5  6  7  8  9       8  9 10 11 12 13 14       5  6  7  8  9 10 11
13 14 15 16 17 18 19      10 11 12 13 14 15 16      15 16 17 18 19 20 21      12 13 14 15 16 17 18
20 21 22 23 24 25 26      17 18 19 20 21 22 23      22 23 24 25 26 27 28      19 20 21 22 23 24 25
27 28 29 30 31            24 25 26 27 28 29 30      29 30 31                  26 27 28 29 30 31

     September                  October                   November                  December
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
                   1          1  2  3  4  5  6                   1  2  3                         1
 2  3  4  5  6  7  8       7  8  9 10 11 12 13       4  5  6  7  8  9 10       2  3  4  5  6  7  8
 9 10 11 12 13 14 15      14 15 16 17 18 19 20      11 12 13 14 15 16 17       9 10 11 12 13 14 15
16 17 18 19 20 21 22      21 22 23 24 25 26 27      18 19 20 21 22 23 24      16 17 18 19 20 21 22
23 24 25 26 27 28 29      28 29 30 31               25 26 27 28 29 30         23 24 25 26 27 28 29
30                                                                            30 31

calendar(year, w=2, l=1, c=6, m=3):以多行字符串形式返回一年的日歷,w每個(gè)單元格寬度,默認(rèn)2,內(nèi)部已做處理,最小寬度為2,l每列換l行,默認(rèn)為1,內(nèi)部已做處理,至少換行1行,c表示月與月之間的間隔寬度,默認(rèn)為6,內(nèi)部已做處理,最小寬度為2,m表示將12個(gè)月分為m列

import calendar

calendar.setfirstweekday(firstweekday=6)
print(calendar.calendar(2018, m=4))

############### 打印結(jié)果如下 ###############
                                               2018

      January                   February                   March                     April
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6                   1  2  3                   1  2  3       1  2  3  4  5  6  7
 7  8  9 10 11 12 13       4  5  6  7  8  9 10       4  5  6  7  8  9 10       8  9 10 11 12 13 14
14 15 16 17 18 19 20      11 12 13 14 15 16 17      11 12 13 14 15 16 17      15 16 17 18 19 20 21
21 22 23 24 25 26 27      18 19 20 21 22 23 24      18 19 20 21 22 23 24      22 23 24 25 26 27 28
28 29 30 31               25 26 27 28               25 26 27 28 29 30 31      29 30

        May                       June                      July                     August
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
       1  2  3  4  5                      1  2       1  2  3  4  5  6  7                1  2  3  4
 6  7  8  9 10 11 12       3  4  5  6  7  8  9       8  9 10 11 12 13 14       5  6  7  8  9 10 11
13 14 15 16 17 18 19      10 11 12 13 14 15 16      15 16 17 18 19 20 21      12 13 14 15 16 17 18
20 21 22 23 24 25 26      17 18 19 20 21 22 23      22 23 24 25 26 27 28      19 20 21 22 23 24 25
27 28 29 30 31            24 25 26 27 28 29 30      29 30 31                  26 27 28 29 30 31

     September                  October                   November                  December
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
                   1          1  2  3  4  5  6                   1  2  3                         1
 2  3  4  5  6  7  8       7  8  9 10 11 12 13       4  5  6  7  8  9 10       2  3  4  5  6  7  8
 9 10 11 12 13 14 15      14 15 16 17 18 19 20      11 12 13 14 15 16 17       9 10 11 12 13 14 15
16 17 18 19 20 21 22      21 22 23 24 25 26 27      18 19 20 21 22 23 24      16 17 18 19 20 21 22
23 24 25 26 27 28 29      28 29 30 31               25 26 27 28 29 30         23 24 25 26 27 28 29
30 

calendar.Calendar(firstweekday=0)類

firstweekday為一個(gè)整數(shù),指定一周的第一天,0是星期一(默認(rèn)),6為星期日

iterweekdays():獲取一周的數(shù)字的迭代器,迭代器的第一個(gè)值與firstweekday的值相同

from calendar import Calendar
c = Calendar()
print(list(c.iterweekdays()))       # [0, 1, 2, 3, 4, 5, 6]-->代表星期一至星期日,0為星期一,即一周的第一天
c = Calendar(firstweekday=6)
print(list(c.iterweekdays()))       # [6, 0, 1, 2, 3, 4, 5]-->代表星期日至星期六,6為星期日,即一周的第一天

itermonthdates(year, month):獲取一個(gè)月日期的迭代器,此迭代器會(huì)返回指定月份的所有日期,包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

from calendar import Calendar

c = Calendar(firstweekday=6)
for item in c.itermonthdates(2018, 8):
    print(item)

############### 打印結(jié)果如下 ###############
2018-07-29
2018-07-30
2018-07-31
2018-08-01
...
2018-08-31
2018-09-01

可以看出,2018-07-29、2018-07-30、2018-07-31正是8月份開(kāi)始的那一周的日期,而2018-09-01為8月份結(jié)束的那一周的日期,8月份所有的日期全部獲取得到!另外注意的是,這里的日期為datatime.date類型!另外,請(qǐng)將星期天設(shè)置為一周的第一天,否則將無(wú)法直觀顯示其作用!

itermonthdays(year, month):返回一個(gè)月天數(shù)的迭代器(不是當(dāng)前月份的天數(shù)為0),此迭代器將返回指定月份的日期數(shù)字,包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

from calendar import Calendar

c = Calendar(firstweekday=6)
for item in c.itermonthdays(2018, 8):
    print(item)

############### 打印結(jié)果如下 ###############
0
0
0
1
...
31
0

因?yàn)?018-07-29、2018-07-30、2018-07-31、2018-09-01不是指定月份的日期,所以為0

itermonthdays2(year, month):返回一個(gè)月天數(shù)與星期的迭代器(不是當(dāng)前月份的天數(shù)為0),此迭代器將返回指定月份的日期數(shù)字與星期幾所代表的數(shù)字組成的元組,包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

from calendar import Calendar

c = Calendar(firstweekday=6)
for item in c.itermonthdays2(2018, 8):
    print(item)
############### 打印結(jié)果如下 ###############
(0, 6)
(0, 0)
(0, 1)
(1, 2)
...
(31, 4)
(0, 5)

可以看出,2018-08-01正是星期三

monthdatescalendar(year, month):返回一個(gè)月日期列表,按周劃分,為一個(gè)二維數(shù)組。包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

from calendar import Calendar

c = Calendar(firstweekday=6)
for item in c.monthdatescalendar(2018, 8):
    print(item)

############### 打印結(jié)果如下 ###############
[datetime.date(2018, 7, 29), datetime.date(2018, 7, 30), datetime.date(2018, 7, 31), datetime.date(2018, 8, 1), datetime.date(2018, 8, 2), datetime.date(2018, 8, 3), datetime.date(2018, 8, 4)]
[datetime.date(2018, 8, 5), datetime.date(2018, 8, 6), datetime.date(2018, 8, 7), datetime.date(2018, 8, 8), datetime.date(2018, 8, 9), datetime.date(2018, 8, 10), datetime.date(2018, 8, 11)]
[datetime.date(2018, 8, 12), datetime.date(2018, 8, 13), datetime.date(2018, 8, 14), datetime.date(2018, 8, 15), datetime.date(2018, 8, 16), datetime.date(2018, 8, 17), datetime.date(2018, 8, 18)]
[datetime.date(2018, 8, 19), datetime.date(2018, 8, 20), datetime.date(2018, 8, 21), datetime.date(2018, 8, 22), datetime.date(2018, 8, 23), datetime.date(2018, 8, 24), datetime.date(2018, 8, 25)]
[datetime.date(2018, 8, 26), datetime.date(2018, 8, 27), datetime.date(2018, 8, 28), datetime.date(2018, 8, 29), datetime.date(2018, 8, 30), datetime.date(2018, 8, 31), datetime.date(2018, 9, 1)]

可以看出,打印出來(lái)的第一個(gè)值為第一周的日期列表,其中還包含了2018-07-29、2018-07-30、2018-07-31三天

monthdayscalendar(year, month):返回一個(gè)月中天數(shù)列表(不是當(dāng)前月份的天數(shù)為0),按周劃分,為一個(gè)二維數(shù)組。包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

from calendar import Calendar

c = Calendar(firstweekday=6)
for item in c.monthdayscalendar(2018, 8):
    print(item)

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

monthdays2calendar(year, month):返回一個(gè)月中天數(shù)與星期的列表(不是當(dāng)前月份的天數(shù)為0),按周劃分,為一個(gè)二維數(shù)組。包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

from calendar import Calendar

c = Calendar(firstweekday=6)
for item in c.monthdays2calendar(2018, 8):
    print(item)

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

yeardatescalendar(year, width=3):返回一年中所有的日期,為一個(gè)4維數(shù)組。width表示將一年中12個(gè)月份進(jìn)行劃分,每width個(gè)月為一份,每一份包含各個(gè)月份,每個(gè)月份包含周,每周包含日期信息。包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

from calendar import Calendar

c = Calendar(firstweekday=6)
for item in c.yeardatescalendar(2018, 3):
    print(item)

############### 打印結(jié)果如下 ###############
[[[datetime.date(2017, 12, 31), datetime.date(2018, 1, 1), datetime.date(2018, 1, 2),...]]]
[[[datetime.date(2018, 4, 1), datetime.date(2018, 4, 2), datetime.date(2018, 4, 3),...]]]
[[[datetime.date(2018, 7, 1), datetime.date(2018, 7, 2), datetime.date(2018, 7, 3),...]]]
[[[datetime.date(2018, 9, 30), datetime.date(2018, 10, 1), datetime.date(2018, 10, 2),...]]]

yeardayscalendar(year, width=3):返回一年中每個(gè)月的天數(shù),為一個(gè)4維數(shù)組。width表示將一年中12個(gè)月份進(jìn)行劃分,每width個(gè)月為一份;每一份包含各個(gè)月份,每個(gè)月份包含周,每周包含天數(shù)信息(不是當(dāng)前月份的天數(shù)為0)。包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

from calendar import Calendar

c = Calendar(firstweekday=6)
for item in c.yeardayscalendar(2018, 3):
    print(item)

############### 打印結(jié)果如下 ###############
[[[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], ...]]]
[[[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], ...]]]
[[[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], ...]]]
[[[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], ...]]]

yeardays2calendar(year, width=3):返回一年中農(nóng)每個(gè)月的天數(shù)與星期的元組,為一個(gè)4維的元組列表。width表示將一年中12個(gè)月份進(jìn)行劃分,每width個(gè)月為一份;每一份包含各個(gè)月份,每個(gè)月份包含周,每周包含天數(shù)與星期的元組信息(不是當(dāng)前月份的天數(shù)為0)。包括月份開(kāi)始那周的所有日期和月份結(jié)束那周的所有日期

from calendar import Calendar

c = Calendar(firstweekday=6)
for item in c.yeardays2calendar(2018, 3):
    print(item)

############### 打印結(jié)果如下 ###############
[[[(0, 6), (1, 0), (2, 1), (3, 2), (4, 3), (5, 4), (6, 5)], [(7, 6), (8, 0), ...]]]
[[[(1, 6), (2, 0), (3, 1), (4, 2), (5, 3), (6, 4), (7, 5)], [(8, 6), (9, 0), ...]]]
[[[(1, 6), (2, 0), (3, 1), (4, 2), (5, 3), (6, 4), (7, 5)], [(8, 6), (9, 0), ...]]]
[[[(0, 6), (1, 0), (2, 1), (3, 2), (4, 3), (5, 4), (6, 5)], [(7, 6), (8, 0), ...]]]

calendar.TextCalendar(firstweekday=0)

Calendar子類,firstweekday為一個(gè)整數(shù),指定一周的第一天,0是星期一(默認(rèn)),6為星期日

formatmonth(theyear, themonth, w=0, l=0):以多行字符串形式返回一個(gè)月的日歷。theyear指定年,themonth指定月,w每個(gè)單元格寬度,默認(rèn)0,內(nèi)部已做處理,最小寬度為2,l每列換l行,默認(rèn)為0,內(nèi)部已做處理,至少換行1行

from calendar import TextCalendar

c = TextCalendar(firstweekday=6)
print(c.formatmonth(2018, 8))

############### 打印結(jié)果如下 ###############
    August 2018
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

prmonth(theyear, themonth, w=0, l=0):打印formatmonth(theyear, themonth, w=0, l=0)的結(jié)果,無(wú)返回值

from calendar import TextCalenadr

c = TextCalendar(firstweekday=6)
c.prmonth(2018, 8)

############### 打印結(jié)果如下 ###############
    August 2018
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

因?yàn)闊o(wú)返回值,所以返回的結(jié)果為None

formatyear(theyear, w=2, l=1, c=6, m=3):以多行字符串形式返回一年的日歷,w每個(gè)單元格寬度,默認(rèn)0,內(nèi)部已做處理,最小寬度為2,l每列換l行,默認(rèn)為0,內(nèi)部已做處理,至少換行1行,c月與月之間的間隔寬度,默認(rèn)為6,內(nèi)部已做處理,最小寬度為2,m表示將12個(gè)月分為m列

from calendar import TextCalendar

c = TextCalendar(firstweekday=6)
print(c.format(2018, m=4))

############### 打印結(jié)果如下 ###############
                                               2018

      January                   February                   March                     April
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6                   1  2  3                   1  2  3       1  2  3  4  5  6  7
 7  8  9 10 11 12 13       4  5  6  7  8  9 10       4  5  6  7  8  9 10       8  9 10 11 12 13 14
14 15 16 17 18 19 20      11 12 13 14 15 16 17      11 12 13 14 15 16 17      15 16 17 18 19 20 21
21 22 23 24 25 26 27      18 19 20 21 22 23 24      18 19 20 21 22 23 24      22 23 24 25 26 27 28
28 29 30 31               25 26 27 28               25 26 27 28 29 30 31      29 30

        May                       June                      July                     August
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
       1  2  3  4  5                      1  2       1  2  3  4  5  6  7                1  2  3  4
 6  7  8  9 10 11 12       3  4  5  6  7  8  9       8  9 10 11 12 13 14       5  6  7  8  9 10 11
13 14 15 16 17 18 19      10 11 12 13 14 15 16      15 16 17 18 19 20 21      12 13 14 15 16 17 18
20 21 22 23 24 25 26      17 18 19 20 21 22 23      22 23 24 25 26 27 28      19 20 21 22 23 24 25
27 28 29 30 31            24 25 26 27 28 29 30      29 30 31                  26 27 28 29 30 31

     September                  October                   November                  December
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
                   1          1  2  3  4  5  6                   1  2  3                         1
 2  3  4  5  6  7  8       7  8  9 10 11 12 13       4  5  6  7  8  9 10       2  3  4  5  6  7  8
 9 10 11 12 13 14 15      14 15 16 17 18 19 20      11 12 13 14 15 16 17       9 10 11 12 13 14 15
16 17 18 19 20 21 22      21 22 23 24 25 26 27      18 19 20 21 22 23 24      16 17 18 19 20 21 22
23 24 25 26 27 28 29      28 29 30 31               25 26 27 28 29 30         23 24 25 26 27 28 29
30                                                                            30 31

pryear(theyear, w=2, l=1, c=6, m=3):將formatyear(theyear, w=2, l=1, c=6, m=3)的結(jié)果作為返回

calendar.HTMLCalendar(firstweekday=0)

Calendar的子類,firstweekday為一個(gè)整數(shù),指定一周的第一天,0是星期一(默認(rèn)),6為星期日

formatmonth(theyear, themonth, withyear=Ture):返回一個(gè)月日歷的html內(nèi)容,withyear是否顯示年份,默認(rèn)為True,即顯示年份

from calendar import HTMLCalendar

c = HTMLCalendar(firstweekday=6)
print(c.formatmonth(2018, 8, withyear=False))

############### 打印結(jié)果如下 ###############
<table border="0" cellpadding="0" cellspacing="0" class="month">
<tr><th colspan="7" class="month">August</th></tr>
<tr><th class="sun">Sun</th><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th></tr>
<tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="wed">1</td><td class="thu">2</td><td class="fri">3</td><td class="sat">4</td></tr>
<tr><td class="sun">5</td><td class="mon">6</td><td class="tue">7</td><td class="wed">8</td><td class="thu">9</td><td class="fri">10</td><td class="sat">11</td></tr>
<tr><td class="sun">12</td><td class="mon">13</td><td class="tue">14</td><td class="wed">15</td><td class="thu">16</td><td class="fri">17</td><td class="sat">18</td></tr>
<tr><td class="sun">19</td><td class="mon">20</td><td class="tue">21</td><td class="wed">22</td><td class="thu">23</td><td class="fri">24</td><td class="sat">25</td></tr>
<tr><td class="sun">26</td><td class="mon">27</td><td class="tue">28</td><td class="wed">29</td><td class="thu">30</td><td class="fri">31</td><td class="noday">&nbsp;</td></tr>
</table>

formatyear(theyear, width=3):返回一年日歷的html內(nèi)容,width表示將12個(gè)月分為width列

from calendar import HTMLCalendar

c = HTMLCalendar(firstweekday=6)
print(c.formatyear(2018, width=4))

formatyearpage(theyear, width=3, css='calendar.css', encoding=None):返回一年日歷的html內(nèi)容,width表示將12個(gè)月分為width列,css可自定義css樣式,encoding編碼方式

from calendar import HTMLCalendar

c = HTMLCalendar(firstweekday=6)
print(c.formatyearpage(2018, width=4))

到此這篇關(guān)于Python標(biāo)準(zhǔn)庫(kù)calendar的使用方法的文章就介紹到這了,更多相關(guān)Python calendar使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • NumPy中的實(shí)用函數(shù)clip詳解

    NumPy中的實(shí)用函數(shù)clip詳解

    這篇文章主要介紹了NumPy中的實(shí)用函數(shù)clip詳解,NumPy函數(shù)clip()用于保留數(shù)組中在間隔范圍內(nèi)的值,給定一個(gè)范圍,范圍外的值將剪裁到范圍邊界,需要的朋友可以參考下的相關(guān)資料
    2023-08-08
  • Python Pandas分組聚合的實(shí)現(xiàn)方法

    Python Pandas分組聚合的實(shí)現(xiàn)方法

    這篇文章主要介紹了Python Pandas分組聚合的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • 利用python中pymysql操作MySQL數(shù)據(jù)庫(kù)的新手指南

    利用python中pymysql操作MySQL數(shù)據(jù)庫(kù)的新手指南

    PyMySQL是在Python3.x版本中用于連接MySQL服務(wù)器的一個(gè)庫(kù),Python2中是使用mysqldb,這篇文章主要給大家介紹了關(guān)于利用python中pymysql操作MySQL數(shù)據(jù)庫(kù)的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • 如何使用Python腳本實(shí)現(xiàn)文件拷貝

    如何使用Python腳本實(shí)現(xiàn)文件拷貝

    這篇文章主要介紹了如何使用Python腳本實(shí)現(xiàn)文件拷貝,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Python字符串詳細(xì)介紹

    Python字符串詳細(xì)介紹

    這篇文章主要介紹了Python字符串詳解,本文講解了字符串相關(guān)知識(shí)、字符串的一些特性、原始字符串、unicode字符串、字符串的常用操作方法、內(nèi)建函數(shù)列表等內(nèi)容,需要的朋友可以參考下
    2015-05-05
  • Python實(shí)現(xiàn)直方圖均衡基本原理解析

    Python實(shí)現(xiàn)直方圖均衡基本原理解析

    這篇文章主要介紹了Python實(shí)現(xiàn)直方圖均衡基本原理,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2019-08-08
  • Python可視化神器pyecharts繪制雷達(dá)圖

    Python可視化神器pyecharts繪制雷達(dá)圖

    這篇文章主要介紹了Python可視化神器pyecharts繪制雷達(dá)圖,雷達(dá)圖是以從同一點(diǎn)開(kāi)始的軸上表示的三個(gè)或更多個(gè)定量變量的二維圖表的形式顯示多變量數(shù)據(jù)的圖形方法
    2022-07-07
  • python 獲取剪切板內(nèi)容的兩種方法

    python 獲取剪切板內(nèi)容的兩種方法

    這篇文章主要介紹了python 獲取剪切板內(nèi)容的兩種方法,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下
    2020-11-11
  • Python爬蟲(chóng)自動(dòng)化獲取華圖和粉筆網(wǎng)站的錯(cuò)題(推薦)

    Python爬蟲(chóng)自動(dòng)化獲取華圖和粉筆網(wǎng)站的錯(cuò)題(推薦)

    這篇文章主要介紹了Python爬蟲(chóng)自動(dòng)化獲取華圖和粉筆網(wǎng)站的錯(cuò)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01
  • 使用Python實(shí)現(xiàn)跳幀截取視頻幀

    使用Python實(shí)現(xiàn)跳幀截取視頻幀

    這篇文章主要介紹了使用Python實(shí)現(xiàn)跳幀截取視頻幀,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05

最新評(píng)論

阿合奇县| 荥经县| 墨玉县| 东港市| 榆树市| 崇礼县| 灵山县| 多伦县| 衡南县| 龙泉市| 高尔夫| 凤山县| 罗城| 绵阳市| 建德市| 河间市| 睢宁县| 革吉县| 织金县| 称多县| 鄂州市| 曲松县| 福清市| 闽清县| 盘山县| 铜川市| 九龙坡区| 宾川县| 清流县| 延庆县| 衢州市| 吉水县| 大安市| 扬中市| 天长市| 重庆市| 深泽县| 鄱阳县| 阿鲁科尔沁旗| 巢湖市| 留坝县|