majuna/app/brm/utils.py

20 lines
465 B
Python

from __future__ import annotations
from typing import Any
def is_integer(n: Any) -> bool:
"""
Determine if a string (or other object type that can be converted automatically) represents an integer.
Thanks to https://note.nkmk.me/en/python-check-int-float/.
:param n: object to test
:return: true if it's an integer
"""
try:
float(n)
except ValueError:
return False
else:
return float(n).is_integer()