【问题标题】:Usage of Interface package results in issubclass() error使用接口包导致 issubclass() 错误
【发布时间】:2018-10-24 14:41:08
【问题描述】:

我目前正在做一个项目,我们决定使用interface 库而不是abc。但是,当我运行我的程序时,会弹出以下错误:

Traceback (most recent call last):
  File "runner.py", line 1, in <module>
    from exchanges import *
  File "/Users/**/Projects/jimmy/characterlib/__init__.py", line 2, in <module>
    from exchanges import hitbtc
  File "/Users/**/Projects/jimmy/characterlib/soldier.py", line 5, in <module>
    class Soldier(implements(ICharacter)):
  File "/usr/local/lib/python3.7/site-packages/interface/interface.py", line 490, in implements
    if not issubclass(I, Interface):
TypeError: issubclass() arg 1 must be a class

现在我的设置非常基础:

士兵.py:

from interface import implements, Interface
import characterlib.ICharacter as ICharacter

class Soldier(implements(ICharacter)):

I字符:

from interface import Interface

class ICharacter(Interface):
    def walk(self): pass

初始化.py:

import characterlib.ICharacter
import characterlib.Soldier

现在您可以看到,设置非常简单,但是我无法让它正常运行。这怎么可能?

有没有人对这个话题有更多的经验?

谢谢。

【问题讨论】:

    标签: python interface


    【解决方案1】:

    您的imports 有点错误。

    import characterlib.ICharacter as ICharacter
    

    表示ICharacter 是一个模块,而不是接口。只需更改类声明即可解决:

    class Soldier(implements(ICharacter.ICharacter)):
        def walk(self):
            pass
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 2021-08-27
      • 2019-08-13
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多