OrderedCounter返回RecursionError

时间:2019-06-12 12:01:38

标签: python python-3.x python-3.6 method-resolution-order

我正在根据{strong> Raymond Hettinger 在PyCon 2015中的讲话尝试点菜柜台。我试图用python 3.6.8做同样的事情

from collections import Counter, OrderedDict

class OrderedCounter(Counter, OrderedDict):

    def __repr__(self):
        return "{}({})".format(self.__class__.__name__,
                               OrderedCounter(self))

    def __reduce__(self):
        return self.__class__, (OrderedCounter(self),)

尝试使用此代码

ox = OrderedCounter("abrac")
ox

回溯如下

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/py30539GwP", line 8, in __repr__
  File "/tmp/py30539GwP", line 8, in __repr__
  File "/tmp/py30539GwP", line 8, in __repr__
  [Previous line repeated 194 more times]
  File "/home/blue/.pyenv/versions/3.6.8/lib/python3.6/collections/__init__.py", line 535, in __init__
    self.update(*args, **kwds)
  File "/home/blue/.pyenv/versions/3.6.8/lib/python3.6/collections/__init__.py", line 614, in update
    if isinstance(iterable, Mapping):
  File "/home/blue/.pyenv/versions/3.6.8/lib/python3.6/abc.py", line 184, in __instancecheck__
    if subclass in cls._abc_cache:
  File "/home/blue/.pyenv/versions/3.6.8/lib/python3.6/_weakrefset.py", line 72, in __contains__
    wr = ref(item)
RecursionError: maximum recursion depth exceeded while calling a Python object

有人可以告诉我可能的原因和解决方案吗?如果我错过了任何内容,或者过分强调或强调了一点,请在评论中告诉我。

0 个答案:

没有答案
相关问题