Python Forum
time.time wont return a useable number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
time.time wont return a useable number
#1
I have been losing it completely for the last two hours over this. It has made my project suddenly fail completely.

ALL I WANT IS TO BE ABLE TO PERFORM SIMPLE ARITHMETIC ON A NUMBER RETURNED FROM time.time.

Apologies for the caps there but i have lost my temper really badly on this - EVERY reference states that time.time returns a float number, which suggests it should be ready for trying arithmetic, but every attempt i make to do this ends with an error of multiple different types.

My code should be quite simply recording time to a variable, i know this works, as i print the time frequently and its fine, but when i try to perform arithmetic it fails. First, it states that i am attempting to perform arithmetic on a function, suggesting that instead of actually assigning the value of time.time returned to the variable, it is in fact assigning the variable to be an alias of the function, thereby creating a newly names version of the function instead of performing the function and giving me my value.

I have tried casting its value to a type, both integer and float value, and i have searched the internet extensively, but to no avail.

I apologise that the tone of my message is somewhat angry - i have been beating my head against the wall it feels like for hours, because a function doesnt operate the way the entire internet suggests it should, inclusive of the manual for python.

The code should operate as follows. I am aware that this snippet actually does nothing, i have removed the functional code such that all which remains is the offending article, i have also reformatted it to make sure it is runnable, even if it is useless as this appears.

Thanks in advance for any help offered.

(this actually runs as part of over a thousand lines of code, running inside one of multiple threads... seems very confuising if i posted it all here)

Its using tesseract to acquire some text, which all runs perfectly, the aim here is to check if it has received the same response three times in a row.

I am also very much aware that in this format it would likely create an infinite loop. in the context of the program, this small snippet exists between a carefully laid out set of sleeps to manage my threads, and so the infinite loop should be ignored here.
while (active==true):
     if "Word" in text:
          temptime=time.time()
          print("Word Text Found")
          textcyclelength=int(textcyclelength * 1000)
          temptime=int(temptime * 1000)
          temptime=(textcyclelength-temptime)
          if (textrepeat > 2) and (textcyclelength < 3000):
               textcyclelength=time.time
               typing=True
               texttotype="text1"
               textrepeats=0
          elif (textcyclelength < 3000):
               textcyclelength=time.time
               typing=True
               texttotype="text2"
               textrepeats=textrepeats+1
         elif (textcyclelength > 3000):
               textcyclelength=time.time
               typing=True
               texttotype="text3"
               textrepeats=0 
Please help, this is driving me nuts. I just want a simple number...

(currently returning TypeError: unsupported operand type(s) for *: 'builtin_function_or_method' and 'int', which is the first error i got.)
Reply
#2
your code is obviously not complete, so there may be other errors, but the one obvious at the moment is that on lines 9, 14, 19 you have time.time, instead of time.time().
that said, your code badly need refactoring (no offence)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Firstly, thanks for your swift response. :)

What do you mean by refactoring please?

I am a self taught coder so i dont really have much in the way of direction. What i would have wanted to use, before ineffective google searches got involved, is below.

The original code was copied from my current state but the code below is basically what i had to begin with, but threw the same error as above.

Again, simplified to only the relevant parts.

temptime=time.time()
textlooptime=time.time()
textrepeats=0
while (true):
      temptime=textlooptime - time.time()
      if (textrepeats > 2):
             # this is where the catch out responds to 
             # repeated short intervals
             textlooptime=time.time()
             textrepeats=0
      elif temptime > 3:
             # do the first lot - we detected a long 
             # enough interval
             textrepeats = 0
             textlooptime=time.time()
      elif (temptime <= 3):
             # do the second lot, interval too short.
             textrepeats = textrepeats + 1
             textlooptime=time.time()
Clearly, the code is different, but im out and on mobile.
I know my syntax was correct (: etc) on the firstlot because idle wont let it run until thats covered. The code runs on a thread and actually closes the thread when this happens, making the rest of the program go haywire.

I have simplified this way as this is the only change made, and its the only thing im having trouble with.

Thanks again :)

- edited - forgot some declarations
Reply
#4
(Nov-15-2018, 02:12 PM)Nyscersul Wrote: he original code was copied from my current state but the code below is basically what i had to begin with, but threw the same error as above.
please, post runnable snippet that reproduce the error (in python tags) as well as the full traceback you get in error tags. In the new code you don't have multiplication, so it's not possible to have the same error from the above code
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
I was just sitting down to try to figure out how to send the code structure sensibly without placing the entire file here, but then...

I think that i must have had the same syntax error in the first place, and the error message led me to believe that in fact the problem was the function not the syntax. (time.time instead of time.time() )

Epic Fail on my part.

The continued existence of this thread would be wasteful to this community, as it does nothing for reference.

As you are a moderator, please take note of my thanks, and then delete this thread :)

And, have a nice afternoon/morning/evening whatever :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Date Time Series Help...Please spra8560 2 313 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Python date format changes to date & time 1418 4 518 Jan-20-2024, 04:45 AM
Last Post: 1418
  time difference bettwenn logs enkliy 14 875 Nov-21-2023, 04:51 PM
Last Post: rob101
Question Need Help with Vehicle Routing Problem with Time Windows (VRPTW) in Python kasper321421312 1 506 Nov-10-2023, 08:19 PM
Last Post: snippsat
  How do I stream and record at the same time with arducam? traderjoe 0 430 Oct-23-2023, 12:01 AM
Last Post: traderjoe
  i tried to install python for the first time today and pretty certain im being remote brianlj 2 505 Oct-03-2023, 11:15 AM
Last Post: snippsat
  Why wont this path work one way, but will the other way? cubangt 2 623 Sep-01-2023, 04:14 PM
Last Post: cubangt
  [Python 2.7] Why can't I press [ESC] a fourth time? Ashwood 3 621 Aug-27-2023, 02:01 PM
Last Post: deanhystad
  Hard time trying to figure out the difference between two strings carecavoador 2 644 Aug-16-2023, 04:53 PM
Last Post: carecavoador
  return next item each time a function is executed User3000 19 2,175 Aug-06-2023, 02:29 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020