当前位置: 首页>>代码示例>>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;未经允许,请勿转载。