0 python
我试图找出为什么我的python代码给我以下错误(我在这里阅读其他帖子,但我找不到问题).错误如下:
"test_block/top_block.py", line 33, in __init__
0, 0, 0, 0, 0, 1, 1, 1)
TypeError: unbound method make() must be called with my_block instance as first argument (got int instance instead)"
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
class top_block(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="Top Block")
_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
self.samp_rate = samp_rate = 32000
self.extras_my_block_0 = gr_extras.my_block(2, 29, 10, 0, -0.1, 0.1, -0.01,
0, 0, 0, 0, 0, 1, 1, 1)
self.extras_message_dumper_0 = gr_extras.message_dumper()
self.connect((self.extras_my_block_0, 0), (self.extras_message_dumper_0, 0))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
if __name__ == '__main__':
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
(options, args) = parser.parse_args()
tb = top_block()
tb.Run(True)
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助,
何塞
此代码重现您的错误:
class gr_extras(object):
def my_block(self, *args):
return args
class top_block(object):
def __init__(self):
gr_extras.my_block(1, 2)
v = top_block()
Run Code Online (Sandbox Code Playgroud)
执行时:
TypeError: unbound method my_block() must be called with gr_extras
instance as first argument (got int instance instead)
Run Code Online (Sandbox Code Playgroud)
你在没有实例化的情况下调用其他类中的方法.这有效:
class top_block(object):
def __init__(self):
gr = gr_extras()
gr.my_block(1, 2)
Run Code Online (Sandbox Code Playgroud)