gpt4 book ai didi

python - "datetime.date"类型的对象在python中没有len()”

转载 作者:行者123 更新时间:2023-12-02 02:09:53 25 4
gpt4 key购买 nike

我在odoo 11中有这样的代码

@api.multi
def report_team(self):
teambao = self.env['hr.department'].search([])
tongteam = len(teambao)
i = 0
while i < tongteam:
if teambao[i].id:
now = datetime.now()
print(now.date())

project = self.env['project.project'].search([('deadline', '=', now.date())])
print (project)
i = i + 1

当我运行这个函数时,它会出现这样的错误

"object of type 'datetime.date' has no len()" while evaluating 'model.report_team()' 
in report_team
project = self.env['project.project'].search([('deadline', '=', now.date())])

我想要的只是获得今天截止日期的项目

有什么建议给我吗?

谢谢

最佳答案

您应该将日期转换为字符串以进行比较:

project = self.env['project.project'].search([('deadline', '=', str(now.date()))])

关于python - "datetime.date"类型的对象在python中没有len()”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52846048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com