Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:什么是';本周';HTMLCalendar中formatweek()方法中的参数?_Python_Django_Calendar - Fatal编程技术网

Python:什么是';本周';HTMLCalendar中formatweek()方法中的参数?

Python:什么是';本周';HTMLCalendar中formatweek()方法中的参数?,python,django,calendar,Python,Django,Calendar,我正在用Python/Django制作一个web应用程序,并试图在calendar模块中使用HTMLCalendar类制作一个显示会议的日历。 我正在覆盖HTMLCalendar中的formatday()、formatweek()和formatmonth()方法 我已经为formatday()函数编写了新代码。我找到了两个formatweek()函数的代码示例,演示了它的用法: # Sample 1 def formatweek(self, theweek, events): w

我正在用Python/Django制作一个web应用程序,并试图在calendar模块中使用HTMLCalendar类制作一个显示会议的日历。 我正在覆盖HTMLCalendar中的
formatday()
formatweek()
formatmonth()
方法

我已经为
formatday()
函数编写了新代码。我找到了两个
formatweek()
函数的代码示例,演示了它的用法:

# Sample 1
def formatweek(self, theweek, events):
        week = ''
        for d, weekday in theweek:
            week += self.formatday(d, events)
        return f'<tr> {week} </tr>'

# Sample 2
def formatweek(self, theweek, width):
        """
        Returns a single week in a string (no newline).
        """
        return ' '.join(self.formatday(d, wd, width) for (d, wd) in theweek)
#示例1
def formatweek(自我、theweek、事件):
周=“”
对于d,一周中的工作日:
周+=自我形成日(d,事件)
返回f'{week}'
#样本2
def formatweek(自身、周、宽度):
"""
以字符串形式返回一周(无换行符)。
"""
返回“”。为周中的(d,wd)加入(self.formatday(d,wd,width)
我不确定week参数到底是什么。我在网上搜索了
formatweek()
的文档,但找不到任何概述了
week
参数的内容。非常感谢您提供的任何见解。

从模块的源代码来看,
formatweek
似乎需要一个
(日数、工作日数)
元组数组作为
Week
参数的值

您可以为此使用API。根据函数docs字符串

这将返回一个表示一个月日历的矩阵。每行 代表一周;周条目为(日数、工作日数) 元组。本月以外的天数为零

>>> from calendar import TextCalendar
>>> cal = TextCalendar()
>>> for week in cal.monthdays2calendar(2019, 11):
...     print(cal.formatweek(week, 10))
...
                                                 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