prmonth(theyear, themonth, w=0, l=0)
打印指定年和月的日历。格式与formatmonth()函数一样。
样例:
#python 3.4
import calendar
cal = calendar.TextCalendar(0)
cal.prmonth(2015, 11)
cal.prmonth(2015, 11, w = 5)
cal.prmonth(2015, 11, w = 0, l = 2)
结果输出例如以下:
November 2015
Mo Tu We Th Fr Sa Su
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
November 2015
Mon Tue Wed Thu Fri Sat Sun
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
November 2015
Mo Tu We Th Fr Sa Su
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
formatyear(theyear, w=2, l=1, c=6, m=3)
返回指定年的全部月的日历。參数w是给示列与列之间宽度。參数l是表示行与与之间宽度,參数m是表示月与月之间的宽度。
样例:
#python 3.4
import calendar
cal = calendar.TextCalendar(0)
print(cal.formatyear(2015))
结果输出例如以下:
2015
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 1 1
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29
30 31
April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30
July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 1 2 3 4 5 6
6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13
13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20
20 21 22 23 24 25 26 17 18 19 20 21 22 23 21 22 23 24 25 26 27
27 28 29 30 31 24 25 26 27 28 29 30 28 29 30
31
October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 1 1 2 3 4 5 6
5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31
30
pryear(theyear, w=2, l=1, c=6, m=3)
打印指定年的日历。格式按formatyear()函数一样。
样例:
#python 3.4
import calendar
cal = calendar.TextCalendar(0)
cal.pryear(2015)
结果输出例如以下:
2015
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 1 1
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29
30 31
April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30
July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 1 2 3 4 5 6
6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13
13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20
20 21 22 23 24 25 26 17 18 19 20 21 22 23 21 22 23 24 25 26 27
27 28 29 30 31 24 25 26 27 28 29 30 28 29 30
31
October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 1 1 2 3 4 5 6
5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31
30
class calendar.HTMLCalendar(firstweekday=0)
这是创建一个生成HTML内容的日历。
样例:
#python 3.4
import calendar
cal = calendar.HTMLCalendar(0)
print(cal)
输出结果例如以下:
<calendar.HTMLCalendar object at 0x02CA0E30>
HTMLCalendar类的实例方法例如以下:
formatmonth(theyear, themonth, withyear=True)
返回指定年和月的HTML表格的日历。假设withyear为True在表头的标题里包含年份,否则仅仅有月份作为标题。
样例:
#python 3.4
import calendar
cal = calendar.HTMLCalendar(0)
print(cal.formatmonth(2015, 11))
结果输出例如以下:
<table border="0" cellpadding="0" cellspacing="0" class="month">
<tr><th colspan="7" class="month">November 2015</th></tr>
<tr><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><th class="sun">Sun</th></tr>
<tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="sun">1</td></tr>
<tr><td class="mon">2</td><td class="tue">3</td><td class="wed">4</td><td class="thu">5</td><td class="fri">6</td><td class="sat">7</td><td class="sun">8</td></tr>
<tr><td class="mon">9</td><td class="tue">10</td><td class="wed">11</td><td class="thu">12</td><td class="fri">13</td><td class="sat">14</td><td class="sun">15</td></tr>
<tr><td class="mon">16</td><td class="tue">17</td><td class="wed">18</td><td class="thu">19</td><td class="fri">20</td><td class="sat">21</td><td class="sun">22</td></tr>
<tr><td class="mon">23</td><td class="tue">24</td><td class="wed">25</td><td class="thu">26</td><td class="fri">27</td><td class="sat">28</td><td class="sun">29</td></tr>
<tr><td class="mon">30</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr>
</table>
formatyear(theyear, width=3)
返回指定年的一年日历的HTML表格,參数width是指定一个月几行排列。
样例:
#python 3.4
import calendar
cal = calendar.HTMLCalendar(0)
print(cal.formatyear(2015))
结果输出例如以下:
<table border="0" cellpadding="0" cellspacing="0" class="year">
<tr><th colspan="3" class="year">2015</th></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month">
<tr><th colspan="7" class="month">January</th></tr>
<tr><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><th class="sun">Sun</th></tr>
...
formatyearpage(theyear, width=3, css='calendar.css', encoding=None)
返回指定年的一年HTML完整网页的日历。參数width是指定一个月排列多少行。參数css是指定页面使用的类型,參数encoding是指定网页的编码。默认是系统编码。
样例:
#python 3.4
import calendar
cal = calendar.HTMLCalendar(0)
print(cal.formatyearpage(2015))
结果输出例如以下:
b'<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="calendar.css" /> <title>Calendar for 2015</title> </head> <body> <table border="0" cellpadding="0" cellspacing="0" class="year"> <tr><th colspan="3" class="year">2015</th></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month"> <tr><th colspan="7" class="month">January</th></tr> <tr><th class="mon">Mon</th><th class="tue">
...
1</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr> </table> </td></tr></table></body> </html> '
class calendar.LocaleTextCalendar(firstweekday=0, locale=None)
这是一个TextCalendar的子类,通过构造函数来设定不同地区的日历。
class calendar.LocaleHTMLCalendar(firstweekday=0, locale=None)
这是一个HTMLCalendar的子类,通过构造函数来设定不同地区的日历。
蔡军生 QQ:9073204 深圳