代码之家  ›  专栏  ›  技术社区  ›  Elliot

python:typeerror:“float”对象不可调用

  •  0
  • Elliot  · 技术社区  · 15 年前

    我尝试使用以下代码连接2个字符串:

    def __get_temp(self):
        return float(self.ask('RS'))
    
    def __set_temp(self, temp):
        set = ('SS' + repr(temp))
        stat = self.ask(set)
        return self.check(stat)
    
    temp = property(__get_temp, __set_temp)
    

    然后,我一起使用pyvisa通过串行总线发送信号。但是,当我试图调用函数时,我得到

    Traceback (most recent call last):
    File "<pyshell#4>", line 1, in <module>
    chil.temp(13)
    TypeError: 'float' object is not callable
    

    我试着四处寻找这个错误的解释,但没有一个是有意义的。有人知道发生了什么事吗?

    1 回复  |  直到 15 年前
        1
  •  7
  •   Mark Byers    15 年前

    看起来你想设置属性温度,但实际上你要做的是 得到 属性,然后尝试使用参数13将其作为函数调用。设置的语法是:

    chil.temp = 13