首页 > 解决方案 > 为什么过滤器会在父级上引发不可调用的错误

问题描述

我有一个名为MyFilter. 在其中一种方法中,我过滤了一个列表:

def __gatherCommits(self, head, count=2, commits=[]):
    next_commits = self.repo.iter_commits(head, max_count=count)
    filtered_commits = list(filter(lambda x: x.committed_date == self.current_day, next_commits))

最后一行导致抛出错误:

File "MyFilter.py", line 22, in __gatherCommits
    filtered_commits = list(filter(lambda x: x.committed_date == self.current_day, next_commits))
TypeError: 'MyFilter' object is not callable

当我删除违规行时,它按预期运行。

标签: pythoncallable

解决方案


就是这样。谢谢各位。我通过使用变量实例化类的实例来测试类filter。:掌心:


推荐阅读