宽客秀

宽客秀

Quant.Show的Web3站点,Archives from quant.show

从 datetime 导入 datetime

从 datetime 模块导入 datetime

The first datetime in the above code refers to datetime.py, and the second datetime refers to the datetime class.

从 datetime 模块导入 datetime
DATE_Y_FMT = '% Y' #获取年份
div_data['year'] = div_data['EndDate'].map(lambda x.strftime(x, DATE_Y_FMT))

The datetime in the above code refers to the datetime class.

从 datetime 模块导入 datetime
d1 = datetime.date(2018,10,24)
TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'int'

Similar to the previous code, the datetimes here refer to the datetime class, not datetime.py. The datetime class should call the date class at the same level, which is obviously incorrect. (datetime.py includes date class, time class, datetime class, etc.) So how should it be modified?

Modification method 1: After loading the date class, call it directly

从 datetime 模块导入 date
d2 = date(2018,10,24)

Modification method 2: Load the entire datetime.py and then call it using datetime.date

import datetime
d3 = datetime.date(2018,10,24)

A similar issue has also been discussed on Stack Overflow, please refer to the following link: /questions/5619489/troubleshooting-descriptor-date-requires-a-datetime-datetime-object-but-rec

Finally, I would like to share a toolset on GitHub for obtaining date and time and converting them to timestamps.

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。