На этом шаге мы рассмотрим методы этих классов.
Экземпляры классов HTMLCalendar и LocaleHTMLCalendar имеют следующие методы:
>> import calendar >> c = calendar.HTMLCalendar(0) >> print(c.cssclasses) ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
>> с = calendar.LocaleHTMLCalendar (0, "Russian_Russia. 1251" ) >> c.cssclasses = ["workday", "workday", "workday", "workday", "workday", "week-end", "week-end"] >> print (c.formatmonth (2017, 12, False)) <table border="0" cellpadding="0" cellspacing="0" class="month"> <tr><th colspan="7" class="month">December</th></tr> <tr><th class="workday">Mon</th><th class="workday">Tue</th> <th class="workday">Wed</th><th class="workday">Thu</th> <th class="workday">Fri</th><th class="week-end">Sat</th> <th class="week-end">Sun</th></tr> <tr><td class="noday"> </td><td class="noday"> </td> <td class="noday"> </td><td class="noday"> </td><td class="workday">1</td> <td class="week-end">2</td><td class="week-end">3</td></tr> <tr><td class="workday">4</td><td class="workday">5</td><td class="workday">6</td> <td class="workday">7</td><td class="workday">8</td><td class="week-end">9</td> <td class="week-end">10</td></tr> <tr><td class="workday">11</td><td class="workday">12</td><td class="workday">13</td> <td class="workday">14</td><td class="workday">15</td><td class="week-end">16</td> <td class="week-end">17</td></tr> <tr><td class="workday">18</td><td class="workday">19</td><td class="workday">20</td> <td class="workday">21</td><td class="workday">22</td><td class="week-end">23</td> <td class="week-end">24</td></tr> <tr><td class="workday">25</td><td class="workday">26</td><td class="workday">27</td> <td class="workday">28</td><td class="workday">29</td><td class="week-end">30</td> <td class="week-end">31</td></tr> </table>
>> с = calendar.LocaleHTMLCalendar (0, "Russian_Russia. 1251" ) >> print (с.formatyear (2017, 4))
>> с = calendar.LocaleHTMLCalendar (0, "Russian_Russia. 1251" ) >> xhtml = c.formatyearpage (2017, 4, encoding="windows-1251") >> type(xhtml) # Возвращаемая строка имеет тип данных bytes <class 'bytes'> >> print (xhtml.decode ("cp1251") )
На следующем шаге мы рассмотрим другие полезные функции.