0

I've trying to figure out why my python code is giving me the following error (I read other post here, but I cannot find the issue). The error is the following:

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

My code is the following:

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)

Thanks for your help,

Jose

4

1 回答 1

5

此代码重现您的错误:

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

执行时:

TypeError: unbound method my_block() must be called with gr_extras
    instance as first argument (got int instance instead)

您在没有实例化的情况下在其他类中调用方法。这有效:

class top_block(object):
    def __init__(self):
        gr = gr_extras()
        gr.my_block(1, 2)
于 2012-09-28T08:23:12.980 回答