知识卡片

问题卡 · 5714.b

日历月不能用固定天数替代

理解等级:中级

按月推进日期时,月份的天数可变,timedelta因此不接受months。dateutil.relativedelta可表达按日历月变化,或把两个日期的差分解为月与日;这与固定总天数是不同描述。应先说明要日历位置变化还是固定时长,遇到月末还需按相应日历规则判断,不能统一写成加30天。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      timedelta(months=1) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'months' is an invalid keyword ar

    参考来源

    - 位置:《Python Cookbook(第3版)中文版》3.12 时间换算(spine11;extracted/Python Cookbook(第3版)中文版/_epub-src/OEBPS/Text/part0009.xhtml;u056-ch03-020)。 - 结论依据:完整读取本条问题、所有示例与讨论;明确修改语义、区间边界和日历规则,版本纠错已查相应官方说明。 - 原始内容:timedelta(months=1) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'months' is an invalid keyword ar