Python Forum
timedelta object cannot be interpreted as integer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
timedelta object cannot be interpreted as integer
#2
To check if something is in a valid range, you could do following:

minimum_value <= current_value <= maximum_value
All three values should be the same data type.
In your example self.validity should be a timedelta object.

This should work:

                elif self.certification_status == "Fit" and timedelta(days=730) <= self.validity <= timedelta(days=732)):
                    return "Normal"
A example with ip addresses:
from ipaddress import ip_address


def ip_is_in_range(ip, start, end):
    start = ip_address(start)
    end = ip_address(end)
    ip = ip_address(ip)
    return start <= ip <= end
What you've tried with the range object, works for integers.
my_range = range(16, 31, 2)
18 in my_range
17 in my_range
...

# And you can use the range object again and again.
for i in my_range:
    for j in my_range:
        print(i, j)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: timedelta object cannot be interpreted as integer - by DeaD_EyE - Jan-28-2020, 04:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  float object can't be interpreted as an integer t23 2 1,091 Jan-18-2025, 07:36 PM
Last Post: deanhystad
  Are list/dict comprehensions interpreted really sequentially? anata2047 3 2,372 May-31-2022, 08:43 PM
Last Post: Gribouillis
  Convert timedelta to specified format Planetary_Assault_Systems 3 12,852 Jun-27-2021, 01:46 PM
Last Post: snippsat
  Running scripts and location of saved interpreted user-defined classes and functions leodavinci1990 3 3,489 Aug-25-2020, 03:43 AM
Last Post: micseydel
  TypeError: unsupported operand type(s) for *: 'datetime.timedelta' and 'float' chris0147 2 42,601 May-01-2018, 07:20 PM
Last Post: nilamo
  Question about how python being interpreted. Nirelg 2 4,364 May-10-2017, 01:09 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

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