0
votes

I am currently getting this error in my code

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

I have not seen an exact instance to mine I have seen some changes to dtype=object but I am unsure how to implement that and why I would need to. This is a pretty straight forward function.

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)
2
Your time argument is shadowing the time module. You don't even seem to be using the argument, just remove it - sshashank124
Check out if the below solution solves you query. - Vaibhav

2 Answers

1
votes
import time

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

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

Don't use module name time as keyword here:

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

I guess this is the solution you are looking for:

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