Utility class to check data type.
Module sppas.src.utils
Class sppasType
Description
Public functions
is_bool
Check if the entry is boolean.
Parameters
- entry: (any type)
Returns
- (bool)
View Source
@staticmethod
def is_bool(entry):
"""Check if the entry is boolean.
:param entry: (any type)
:returns: (bool)
"""
return str(entry) in ['True', 'False']
is_number
Check if the entry is numeric.
Parameters
- entry: (any type)
Returns
- (bool)
View Source
@staticmethod
def is_number(entry):
"""Check if the entry is numeric.
:param entry: (any type)
:returns: (bool)
"""
try:
float(entry)
return True
except (TypeError, ValueError):
pass
try:
import unicodedata
unicodedata.numeric(entry)
return True
except (TypeError, ValueError):
pass
return False
is_dict
Check if the entry is of any type of dictionary.
Parameters
- entry: (any type)
Returns
- (bool)
View Source
@staticmethod
def is_dict(entry):
"""Check if the entry is of any type of dictionary.
:param entry: (any type)
:returns: (bool)
"""
if type(entry) is dict:
return True
if 'collections.' in str(type(entry)):
return True
return False