SPPAS 4.20

Module sppas.src.utils

Class sppasType

Description

Utility class to check data type.

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