gpt4 book ai didi

python - 类型错误 : object of type 'filter' has no len()

转载 作者:行者123 更新时间:2023-12-01 07:11:08 27 4
gpt4 key购买 nike

执行 Python 脚本时,我收到以下错误...

Traceback (most recent call last):
File "/usr/local/bin/jira-cycle-extract", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/jira_cycle_extract/cli.py", line 144, in main
cycle_data = q.cycle_data(verbose=args.verbose)
File "/usr/local/lib/python3.7/site-packages/jira_cycle_extract/cycletime.py", line 141, in cycle_data
for snapshot in self.iter_changes(issue, False):
File "/usr/local/lib/python3.7/site-packages/jira_cycle_extract/query.py", line 114, in iter_changes
last_status = status_changes[0].fromString if len(status_changes) != 0 else issue.fields.status.name
TypeError: object of type 'filter' has no len()

我尝试通过根据其他研究添加以下代码来解决此问题,并将 > 0 更改为 notempty 或其他形式以检查是否为空名单,但没有运气。

这是有问题的代码...

status_changes = filter(
lambda h: h.field == 'status',
itertools.chain.from_iterable([c.items for c in issue.changelog.histories])
)

last_status = status_changes[0].fromString if len(status_changes) != 0 else issue.fields.status.name
last_resolution = None

最佳答案

您可以使用带有生成器表达式和默认值的 next 函数。您问题中的代码可以重写为:

last_status = next((h.fromString for c in issue.changelog.histories for h in c.items if h.field == 'status'), issue.fields.status.name)
last_resolution = None

关于python - 类型错误 : object of type 'filter' has no len(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58211348/

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