Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';浮动';对象不可调用错误_Python - Fatal编程技术网

Python ';浮动';对象不可调用错误

Python ';浮动';对象不可调用错误,python,Python,我在我写的一个类中有一个函数,它读取磁强计上的读数,并将其转换为0到359度之间的方向。功能如下: def heading(self): self.xzy = self.__GetCompassMag() self.x = self.xzy[0] self.y = self.xzy[2] pi = 3.14159 self.heading = round((math.atan2(self.y, self.x) * 180) / pi) if se

我在我写的一个类中有一个函数,它读取磁强计上的读数,并将其转换为0到359度之间的方向。功能如下:

def heading(self):
    self.xzy = self.__GetCompassMag()
    self.x = self.xzy[0]
    self.y = self.xzy[2]
    pi = 3.14159
    self.heading = round((math.atan2(self.y, self.x) * 180) / pi)

    if self.heading < 0:
        return int(360 + self.heading)
    else:
        return int(self.heading)
def标题(self):
self.xzy=self.\uu GetCompassMag()
self.x=self.xzy[0]
self.y=self.xzy[2]
pi=3.14159
self.heading=四舍五入((数学atan2(self.y,self.x)*180)/pi)
如果自航向<0:
返回整数(360+自航向)
其他:
返回整型(自航向)

当我尝试使用
print obj.heading()
调用函数时,python shell给出错误“TypeError:'float'对象不可调用”。我在编码方面有一些经验,但在python方面没有太多经验。有人知道这里发生了什么吗?

因为您在此行的普通实例变量中重写了
heading
方法

self.heading = round((math.atan2(self.y, self.x) * 180) / pi
不要使用
self
编写局部变量,因为使用
self
将引用实例变量,请尝试执行以下操作:

def heading(self):
    self.xzy = self.__GetCompassMag()
    self.x = self.xzy[0]
    self.y = self.xzy[2]
    pi = 3.14159
    heading = round((math.atan2(self.y, self.x) * 180) / pi)

    if heading < 0:
        return int(360 + heading)
    else:
        return int(heading)
def标题(self):
self.xzy=self.\uu GetCompassMag()
self.x=self.xzy[0]
self.y=self.xzy[2]
pi=3.14159
标题=圆形((数学atan2(self.y,self.x)*180)/pi)
如果标题<0:
返回整数(360+航向)
其他:
返回整数(标题)
需要:

print obj.heading
取下支架。不管怎样,我看到了这一点,因为我在使用对象执行自己的项目时遇到了相同的问题。(当然我在使用python 3)

希望这有帮助

print obj.heading