导入日历0

时间:2018-08-04 15:39:47

标签: python-3.x python-3.6

当我在python中导入日历并运行此代码时,我不知道为什么它会生成0:

>>> import calendar
>>> c = calendar.TextCalendar(calendar.Sunday)
>>> for i in c.itermonthdays(2025, 4):
        print (i)

它给出了奇怪的结果...开头和结尾的零。

enter image description here

1 个答案:

答案 0 :(得分:0)

阅读itermonthdates的文档:

  

此迭代器将返回整天(作为>>> import re >>> from email import parser, policy >>> email_start = re.compile(r'(?<=\n)\n(?=From:\s+)') >>> parser = parser.Parser(policy=policy.default) >>> for email_text in email_start.split(text): ... message = parser.parsestr(email_text) ... to, from_ = message['to'], message['from'] ... body = message.get_payload() ... print('Email from:', from_) ... print('Email to:', to) ... print('Third line:', body.splitlines(True)[2]) ... Email from: 'Mark Twain' <mark.twain@gmail.com> Email to: 'Edgar Allen Poe' <eap@gmail.com> Third line: I just read the Tell Tale Heart. You've got problems man. Email from: 'Edgar Allen Poe' <eap@gmail.com> Email to: 'Mark Twain' <mark.twain@gmail.com> Third line: The world is crushing my soul, and so are you. 对象)   一个月以及该月初之前或该月末之后的所有天数   整周所需的月份。

itermonthdays使用相同的系统:

  

返回的天数仅仅是月份中的天数。对于那些日子   在指定月份之外,天数为0。

2025年4月starts on a Tuesday,所以第一周的前两天不是四月,上周的后三天也不是。

相关问题