gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:57:38 24 4
gpt4 key购买 nike

我正在尝试将项目从Python 2移植到3,但遇到一些错误。该代码在Python 2.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)

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

global_variables.py

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

抗生素

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小部件,该错误似乎与此处的代码有关:

__初始化__.py

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()

最佳答案

Kivy图形不支持line_width,删除它可以解决问题。

关于python - 将Python 2脚本移植到Python 3时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57181340/

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