TypeError: '>=' not supported between instances of 'builtin_function_or_method' and 'datetime.time'

Question:

I’m trying to compare two datetime.time values but I get this error:

File "c:UsersxxxxxxDesktoppyfichecode.py", line 33, in timeofweek
if (a.time >= d0.time() and a.time() <= d6.time()) or (a.time() >= d21.time() and a.time() <= d23.time()):
TypeError: ‘>=’ not supported between instances of ‘builtin_function_or_method’ and ‘datetime.time’

and this is my code:

def timeofweek(a):
    d6 = a.replace(hour=6, minute=0, second=0, microsecond=0) 
    d21 = a.replace(hour=21, minute=0, second=0, microsecond=0) 
    d0 = a.replace(hour=0, minute=0, second=0, microsecond=0) 
    d23 = a.replace(hour=23, minute=0, second=0, microsecond=0) 
    if a.weekday() in range(0,6):
        print(a.time(),type(a.time())) #for debugging and they are both Datetime.time
        print(d0.time(),type(d0.time())) #for debugging and they are both Datetime.time
        if (a.time() >= d6.time() and a.time() < d21.time()):
            return 1
        if (a.time() >= d0.time() and a.time() < d6.time()) or (a.time() >= d21.time() and a.time() <= d23.time()):
            return 2
    if a.weekday() == 6:
        if (a.time() >= d6.time() and a.time() <= d21.time()):
            return 2
        if (a.time >= d0.time() and a.time() <= d6.time()) or (a.time() >= d21.time() and a.time() <= d23.time()):
            return 3

I’m sure that d6, d21, d0, d23 are all the same type Datetime.time

the problem started when the input value changed from 24h to 12h format, but still when I print the value for debugging I still get the 24h format everytime.

Asked By: zakblack

||

Answers:

you aren’t calling the .time() method for a in the second to last row. (You’re missing brackets)

Answered By: CharlieBONS
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.