當前位置: 首頁>>代碼示例>>Python>>正文


Python calendar.TextCalendar方法代碼示例

本文整理匯總了Python中calendar.TextCalendar方法的典型用法代碼示例。如果您正苦於以下問題:Python calendar.TextCalendar方法的具體用法?Python calendar.TextCalendar怎麽用?Python calendar.TextCalendar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在calendar的用法示例。


在下文中一共展示了calendar.TextCalendar方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_localecalendars

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def test_localecalendars(self):
        # ensure that Locale{Text,HTML}Calendar resets the locale properly
        # (it is still not thread-safe though)
        old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        try:
            cal = calendar.LocaleTextCalendar(locale='')
            local_weekday = cal.formatweekday(1, 10)
            local_month = cal.formatmonthname(2010, 10, 10)
        except locale.Error:
            # cannot set the system default locale -- skip rest of test
            raise unittest.SkipTest('cannot set the system default locale')
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        self.assertEqual(len(local_weekday), 10)
        self.assertGreaterEqual(len(local_month), 10)
        cal = calendar.LocaleHTMLCalendar(locale='')
        local_weekday = cal.formatweekday(1)
        local_month = cal.formatmonthname(2010, 10)
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        self.assertEqual(old_october, new_october) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_calendar.py

示例2: test_locale_calendars

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def test_locale_calendars(self):
        # ensure that Locale{Text,HTML}Calendar resets the locale properly
        # (it is still not thread-safe though)
        old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        try:
            cal = calendar.LocaleTextCalendar(locale='')
            local_weekday = cal.formatweekday(1, 10)
            local_month = cal.formatmonthname(2010, 10, 10)
        except locale.Error:
            # cannot set the system default locale -- skip rest of test
            raise unittest.SkipTest('cannot set the system default locale')
        self.assertIsInstance(local_weekday, str)
        self.assertIsInstance(local_month, str)
        self.assertEqual(len(local_weekday), 10)
        self.assertGreaterEqual(len(local_month), 10)
        cal = calendar.LocaleHTMLCalendar(locale='')
        local_weekday = cal.formatweekday(1)
        local_month = cal.formatmonthname(2010, 10)
        self.assertIsInstance(local_weekday, str)
        self.assertIsInstance(local_month, str)
        new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        self.assertEqual(old_october, new_october) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,代碼來源:test_calendar.py

示例3: __init__

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def __init__(self, master=None, **kw):
        now = datetime.datetime.now()
        fwday = kw.pop('firstweekday', calendar.MONDAY)
        year = kw.pop('year', now.year)
        month = kw.pop('month', now.month)
        sel_bg = kw.pop('selectbackground', '#ecffc4')
        sel_fg = kw.pop('selectforeground', '#05640e')

        super().__init__(master, **kw)

        self.selected = None
        self.date = datetime.date(year, month, 1)
        self.cal = calendar.TextCalendar(fwday)
        self.font = tkfont.Font(self)
        self.header = self.create_header()
        self.table = self.create_table()
        self.canvas = self.create_canvas(sel_bg, sel_fg)
        self.build_calendar() 
開發者ID:PacktPublishing,項目名稱:Tkinter-GUI-Application-Development-Cookbook,代碼行數:20,代碼來源:chapter8_07.py

示例4: cal_command

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def cal_command(message, month=None, year=None):
    """
    一ヶ月のカレンダーを返す
    """
    today = date.today()
    month = int(month) if month else today.month
    year = int(year) if year else today.year

    cal = calendar.TextCalendar(firstweekday=calendar.SUNDAY)
    try:
        botsend(message, '```{}```'.format(cal.formatmonth(year, month)))
    except IndexError:
        # 數字が範囲外の場合は無視する
        pass 
開發者ID:pyconjp,項目名稱:pyconjpbot,代碼行數:16,代碼來源:misc.py

示例5: test_output_textcalendar

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def test_output_textcalendar(self):
        self.assertEqual(
            calendar.TextCalendar().formatyear(2004).strip(),
            result_2004_text.strip()
        ) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_calendar.py

示例6: get_calendar

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def get_calendar(locale, fwday):
    # instantiate proper calendar class
    if locale is None:
        return calendar.TextCalendar(fwday)
    else:
        return calendar.LocaleTextCalendar(fwday, locale) 
開發者ID:TkinterEP,項目名稱:ttkwidgets,代碼行數:8,代碼來源:calendarwidget.py

示例7: test_output_textcalendar

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def test_output_textcalendar(self):
        self.assertEqual(
            calendar.TextCalendar().formatyear(2004),
            result_2004_text
        ) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_calendar.py

示例8: test_formatweekheader_short

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def test_formatweekheader_short(self):
        self.assertEqual(
            calendar.TextCalendar().formatweekheader(2),
            'Mo Tu We Th Fr Sa Su'
        ) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_calendar.py

示例9: test_formatweekheader_long

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def test_formatweekheader_long(self):
        self.assertEqual(
            calendar.TextCalendar().formatweekheader(9),
            '  Monday   Tuesday  Wednesday  Thursday '
            '  Friday   Saturday   Sunday '
        ) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:8,代碼來源:test_calendar.py

示例10: test_formatmonth

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def test_formatmonth(self):
        self.assertEqual(
            calendar.TextCalendar().formatmonth(2004, 1),
            result_2004_01_text
        ) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_calendar.py

示例11: test_prweek

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def test_prweek(self):
        with support.captured_stdout() as out:
            week = [(1,0), (2,1), (3,2), (4,3), (5,4), (6,5), (7,6)]
            calendar.TextCalendar().prweek(week, 1)
            self.assertEqual(out.getvalue().strip(), "1  2  3  4  5  6  7") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_calendar.py

示例12: test_pryear

# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import TextCalendar [as 別名]
def test_pryear(self):
        with support.captured_stdout() as out:
            calendar.TextCalendar().pryear(2004)
            self.assertEqual(out.getvalue().strip(), result_2004_text.strip()) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:test_calendar.py


注:本文中的calendar.TextCalendar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。