[docs]defas_type(value,types=[int,float]):"""Tries to convert value to given data types. Arguments --------- value : object The value to be converted. types : list of types The list of types to try to convert the value to. Returns ------- value : object The value converted to the types if possible. """fortintypes:try:returnt(value)exceptException:passreturnvalue
[docs]defensure(value,dtype):"""Ensure values have a specified type but allowing for None values. Arguments --------- value : object The value to copy dtype : class The class type of the value to be copied. Returns ------- value : object The value with the requested type. """ifvalueisNone:returnNone;else:ifnotisinstance(value,dtype):value=dtype(value);returndtype(value);
# def __copy__(self):# cls = self.__class__# result = cls.__new__(cls)# result.__dict__.update(self.__dict__)# return result## def __deepcopy__(self, memo):# cls = self.__class__# result = cls.__new__(cls)# memo[id(self)] = result# for k, v in self.__dict__.items():# setattr(result, k, deepcopy(v, memo))# return result