gpt4 book ai didi

python-3.x - 接口(interface)继承声明

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

我正在尝试使用由 Github 开发人员开发的旧代码。该代码使用 zope.interface 库中的实现来声明类元素上的接口(interface)。由于库中的实现在 Python 3.6 中不再工作,因此我遇到了以下错误:

TypeError: Class advice impossible in Python3.  Use the @implementer class decorator instead.

几个网站已经解释了如何用@implementer替换implements以在Python 3.6上工作,例如here 。但我还没有找到任何示例来解释当 zope.interface.implements 被用作继承时如何更新代码。代码如下所示:

from zope.interface import implements
class Car(implements(Moveable)):
def __init__(self, x, v, lane, model: IDM, lane_change: LaneChange,
length):
...

我想更新此代码以在 Python 3.6 上工作。我已经尝试过了

@implementer(Moveable) 
class Car:
def __init__(self, x, v, lane, model: IDM, lane_change: LaneChange,
length):

但是不起作用。请帮我弄清楚如何使上述代码在Python 3.6中运行。

最佳答案

以下步骤为我解决了这个问题,

pip uninstall apex
git clone https://www.github.com/nvidia/apex
cd apex
python3 setup.py install

关于python-3.x - 接口(interface)继承声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54822932/

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