Wednesday, 6 July 2016

Python: TextCalendar: prmonth: Print months calendar

prmonth(theyear, themonth, w=0, l=0)

Print months calendar. It internally uses formatmonth() method. ‘w’ specifies the width of the date columns and ‘l’ specifies the number of lines that each week will use.
>>> from calendar import TextCalendar
>>> cal1=TextCalendar()
>>> 
>>> cal1.prmonth(2015, 11)
   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
 >>> 
>>> cal1.prmonth(2015, 11, 1, 1)
   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
 >>> 
>>> cal1.prmonth(2015, 11, 1, 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

 >>> 
>>> cal1.prmonth(2015, 11, 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
 >>> cal1.prmonth(2015, 11, 2, 3)
   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


Previous                                                 Next                                                 Home

Python: TextCalendar: formatmonth: Equivalent of UNIX cal command

formatmonth(theyear, themonth, w=0, l=0)
Returns the months calendar. ‘w’ specifies the width of the date columns and ‘l’ specifies the number of lines that each week will use.
>>> from calendar import TextCalendar
>>> cal1=TextCalendar()
>>> print(cal1.formatmonth(2015, 11, 1, 1))
   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

>>> 
>>> print(cal1.formatmonth(2015, 11, 1, 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


>>> print(cal1.formatmonth(2015, 11, 2, 0))
   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

>>> print(cal1.formatmonth(2015, 11, 2, 1))
   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

>>> print(cal1.formatmonth(2015, 11, 2, 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


Previous                                                 Next                                                 Home

Python: TextCalendar: Generate plain text calendars.

‘calendar.TextCalendar(firstweekday=0)’ is used to generate plain text calendars. Following table summarizes the methods in TextCalendar class.


Method
Description
formatmonth(theyear, themonth, w=0, l=0)
Returns the months calendar. ‘w’ specifies the width of the date columns and ‘l’ specifies the number of lines that each week will use.
prmonth(theyear, themonth, w=0, l=0)
Print months calendar. It internally uses formatmonth() method. ‘w’ specifies the width of the date columns and ‘l’ specifies the number of lines that each week will use.
formatyear(theyear, w=2, l=1, c=6, m=3)
Return m-column calendar year. ‘w’ specifies date column width, ‘l’ specifies lines per week, ‘c’ specifies number spaces between month columns.
pryear(theyear, w=2, l=1, c=6, m=3)
Print the calendar for entire year. It internally uses ‘formatyear’ method. ‘w’ specifies date column width, ‘l’ specifies lines per week, ‘c’ specifies number spaces between month columns.


Previous                                                 Next                                                 Home

Tuesday, 5 July 2016

Python: Calendar: yeardayscalendar(year, width=3)

yeardayscalendar(year, width=3)

Returns the data for given year. Entries in the week lists are day numbers. Day numbers outside this month are zero.
>>> from calendar import Calendar
>>> iter=cal1.yeardayscalendar(2011)
>>> for day in iter:
...     print(day)
... 
[[[0, 0, 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, 0, 0, 0, 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, 0, 0, 0, 0, 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, 0, 0]]]
[[[0, 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, 0]], [[0, 0, 0, 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, 0, 0, 0, 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, 0, 0, 0]]]
[[[0, 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]], [[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, 0, 0, 0]], [[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, 0, 0]]]
[[[0, 0, 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, 0, 0, 0, 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, 0, 0, 0, 0]], [[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]]]


Previous                                                 Next                                                 Home