AttributeError:“Float”对象没有属性“time”

2024-09-30 12:14:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我当前在我的代码中遇到这个错误

AttributeError: 'Float' object has no attribute 'time'

我没有看到一个与我的完全相同的实例我看到了对dtype=object的一些更改,但我不确定如何实现它,以及为什么需要这样做。这是一个非常直接的函数。在

import time

class lastCycle():
    def __init__(self):
        self.lastTime = time.time()
        self.time = 0.0

    def timer(self, time):
        if (time.time() - self.lastTime) > self.time:
            self.lastTime = time.time()
            return True
        else:
            return False

statusUpdate = lastCycle().timer(1.0)

Tags: no代码selfreturnobjecttimedef错误
2条回答

此处不要使用模块名time作为关键字:

def timer(self, time):
    if (time.time() - self.lastTime) > self.time:
        self.lastTime = time.time()
        return True
    else:
        return False

我想这就是你想要的解决方案:

^{pr2}$
import time

类lastCycle(): definit(自身): 自我上次时间= 时间。时间() 自我时间=0.0

^{pr2}$

相关问题 更多 >

    热门问题