1

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
  • 2
    Your time argument is shadowing the time module. You don't even seem to be using the argument, just remove it Commented Jan 2, 2020 at 4:48
  • Check out if the below solution solves you query. Commented Jan 2, 2020 at 4:56

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the input. But the time value was for the self.time not time.time() I see my error was using time as well as declaring self before it.
1
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 Comment

Thank you. I tried changing the variable name before but what I missed was not using self.threshold. I guess I do not need to do this since it is being declared in this function.
0

I got this error when using it, like that: time = my_function() *

and in my_function(): ...code... time.time() ...code...

So, you need to change time *, and it done

1 Comment

This has already been mostly answered - how is your answer better than the other current ones? Does it have any different parts?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.