majuna/app/brm/utils.py

21 lines
465 B
Python
Raw Normal View History

2022-06-15 11:50:15 +01:00
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()