我试图从另一个.py初始化类(extraropt),但它给了我一个错误,我已经搜索但我没有找到解决方案.
下面是我正在调用的一个py的代码:
main.py:
class GameWindow(ui.ScriptWindow):
def __init__(self, stream):
import extraop
exec 'extraop.extraropt().Show(stream)'
Run Code Online (Sandbox Code Playgroud)
这里是我试图调用的一个py的代码(仅限init和del):
extraop.py
class extraropt(ui.Window):
def __init__(self, stream):
ui.Window.__init__(self)
self.BuildWindow()
self.stream=stream
def __del__(self):
ui.Window.__del__(self)
Run Code Online (Sandbox Code Playgroud)
它给出了这个错误:
Error - __init__() takes exactly 2 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)
在线
exec 'extraop.extraropt().Show(stream)'
Run Code Online (Sandbox Code Playgroud)
您extraropt.__init__()通过创建新的实例隐式调用extraopt.在你的代码中,你显示了extraropt.__init__()一个second(stream)参数,所以你必须传入它.
extraop.extraropt(stream).Show()
Run Code Online (Sandbox Code Playgroud)
顺便说一下,没有理由你应该做一个exec而不是像我上面那样明确地调用它.您也没有理由__del__()定义方法,因为您__del__()仍然只调用父方法.
| 归档时间: |
|
| 查看次数: |
2826 次 |
| 最近记录: |