python - 这个答案的python 3版本是什么?
问题描述
我找到了获得几个月最后一天的答案:https ://stackoverflow.com/a/13565185/11661097
这个答案在 python 2 和 python 3 中,当我运行这段代码时,我得到这个错误:
print(self.last_day_of_month(start))
TypeError: last_day_of_month() takes 1 positional argument but 2 were given
start 是一个日期时间对象 (datetime.date(someyear, somemonth, someday) 所以它应该与问题中给出的答案完全相同。
这是因为答案在 python 2 中吗?如果是这样,我将如何重写它以便它在 python 3 中工作?
解决方案
为了last_day_of_month()
- 用作
self
第一个参数,并且 - 用作
start
第二个参数,
所以,做last_day_of_month(self, start)
推荐阅读
- html - 相对定位里面的相对定位有什么作用?
- macros - 为什么这个 Common Lisp 宏不起作用?书上的答题卡错了吗?
- azure-data-factory - 天蓝色数据流将布尔值转换为字符串
- java - 如何格式化日期对象以匹配@JsonFormat?
- powerbi - SnowFlake 和 PowerBI “此值不支持本机查询”
- python - Django 迁移并非未应用
- python - LeakyReLU 中的“负”斜率在哪里?
- sql - SQL Server 使用计算列和用户定义函数根据另一列中的更改来获取日期时间
- java - Java中的资源加载问题
- sql - SSIS 集合将同一数据库的两个版本拉入单个目标进行合并 - 来自一个源的缺失列