将Python 2脚本移植到Python 3时出错

2024-04-26 09:52:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将一个项目从python2移植到python3,但是遇到了一些错误。代码在python2.7.8下运行没有问题。错误如下:

[INFO   ] [Text        ] Provider: sdl2
 Traceback (most recent call last):
   File "C:\Users\xx\PycharmProjects\Simulator\simulator.pyw", line 2, in <module>
     from bin.ui.ui import start
   File "C:\Users\xx\PycharmProjects\Simulator\bin\ui\ui.py", line 30, in <module>
     import bin.global_variables as global_variables
   File "C:\Users\xx\PycharmProjects\Simulator\bin\global_variables.py", line 19, in <module>
     ANTIBIOTICS = {"Generic Antibiotic": Antibiotic("Generic Antibiotic")}
   File "C:\Users\DrPai\PycharmProjects\Simulator\bin\classes\Antibiotic.py", line 17, in __init__
     line_width=1.01)  # SmoothLinePlot
   File "C:\Users\xx\PycharmProjects\Simulator\bin\deps\kivy_graph\__init__.py", line 1031, in __init__
     super(Plot, self).__init__(**kwargs)
   File "kivy\_event.pyx", line 243, in kivy._event.EventDispatcher.__init__
 TypeError: object.__init__() takes exactly one argument (the instance to initialize)

错误所指向的代码的相关部分也包括:

全球_变量.py你知道吗

ANTIBIOTICS = {"Generic Antibiotic": Antibiotic("Generic Antibiotic")}

你知道吗抗生素.py你知道吗

class Antibiotic(object):

    _total_antibiotics = 0  # int

    def __init__(self, name):

        self._id = 'ant' + str(Antibiotic._total_antibiotics)  # str
        self._name = name  # str
        self._line_color = hsv_to_rgb(*NewColor.new_color())  # (R,G,B)
        self._plot = SmoothLinePlot(points=[(0, 0)],
                                    color=self._line_color,
                                    line_width=1.01)  # SmoothLinePlot

        Antibiotic._total_antibiotics += 1

为了绘制绘图,我依赖于从这里(https://github.com/kivy-garden/graph)访问的Kivy Graph小部件,错误似乎与那里的代码有关:

初始化

class Plot(EventDispatcher):
    def __init__(self, **kwargs):
        super(Plot, self).__init__(**kwargs)
        self.ask_draw = Clock.create_trigger(self.draw)
        self.bind(params=self.ask_draw, points=self.ask_draw)
        self._drawings = self.create_drawings()

Tags: inpyselfuibininit错误line