Package: deep-compare
Deep CompareDeep Compare is a simple module that lets the user compare two variables irrespective of their datatype.Installation$ pip install deep-compareRequirementsPython3.7+UsageInstall the Deep Compare package using the command$pipinstalldeep-compareYou will be able to use the package after installation by importing it in your python file.fromdeep_compareimportCompareVariablesCompareVariables includes 11 methods1. is_float(value)returns True if the value is an integer or float, else returns Falsea='17.5'is_float=CompareVariables.is_float(a)print(is_float)Output>>>Truea='hi'is_float=CompareVariables.is_float(a)print(is_float)Output>>>False2. is_date_time(value)returns True if value is a date or date-time(if the input datatype is a string the date or datetime must be in iso time format and the python version used must be 3.7 or above) else returns Falsea='2020-12-12 10:45'is_date_time=CompareVariables.is_date_time(a)print(is_date_time)Output>>>Truea='15th january 2020 'is_date_time=CompareVariables.is_date_time(a)print(is_date_time)Output>>>False3. can_literal_eval(value)returns True if value is a list, dict, tuple, set etc.a='[2,5,6]'can_literal_eval=CompareVariables.can_literal_eval(a)print(can_literal_eval)Output>>>True4. is_complex(value):returns True if value is a complex number else returns Falsea='3 + 5j'is_complex=CompareVariables.is_complex(a)print(is_complex)Output>>>Truea='15th january 2020 'is_complex=CompareVariables.is_complex(a)print(is_complex)Output>>>False5. compare(value1, value2)returns True if the values are equal else returns Falsea=5b=5output=CompareVariables.compare(a,b)print(output)Output>>>Truea=5b='5'output=CompareVariables.compare(a,b)print(output)Output>>>False6. compare_date(value1, value2):returns True if the two input date values(value can be iso time format string also) are equal else returns Falsea='2020-12-12 10:58'b='2020-12-12'output=CompareVariables.compare_date(a,b)print(output)Output>>>Truea='2020-12-12 10:58'b='2020-10-12 10:58'output=CompareVariables.compare_date(a,b)print(output)Output>>>False7. compare_datetime(value1, value2):returns True if the input two input datetime values(value can be iso time format string also) are equal else returns Falsefromdatetimeimportdatetimea='2020-12-12 10:58'b=datetime(2020,12,12,10,58)output=CompareVariables.compare_datetime(a,b)print(output)Output>>>Truea='2020-12-12 10:58'b='2020-12-12 11:58'output=CompareVariables.compare_datetime(a,b)print(output)Output>>>False8. datatype_check(value):returns the input value in its correct datatype else returns Falsea='3 + 4j'output=CompareVariables.datatype_check(a)print(output)Output>>>3+4j9. compare_list_or_tuples_or_set(value1, value2):returns True if the input values(list/tuple/set) are equal else returns Falsea='[1,2,3,44]'b='["1","2","3","44"]'output=CompareVariables.compare_list_or_tuples_or_set(a,b)print(output)Output>>>Truea='[1,2,3,44]'b='["1","2","3"]'output=CompareVariables.compare_list_or_tuples_or_set(a,b)print(output)Output>>>False10. compare_dicts(value1, value2):returns True if the input values(dicts) are equal else returns Falsea='{"1":"2",3:5}'b={1:2,3:5}output=CompareVariables.compare_dicts(a,b)print(output)Output>>>Truea='{"1":"2",3:5}'b={1:2,3:5,4:6}output=CompareVariables.compare_dicts(a,b)print(output)Output>>>False11. deep_compare(value1, value2):returns True if the values are equal irrespective of the input datatype else returns Falsea='{"1":"2",3:5}'b={1:2,3:5}output=CompareVariables.deep_compare(a,b)print(output)Output>>>Truea='[1,2,3,44]'b='["1","2","3"]'output=CompareVariables.deep_compare(a,b)print(output)Output>>>Falsewhen comparing two datetime objects(or datetime string object) if the user only wants to compare the dates they can pass an *arg
in the deep_compare function as shown below:a=datetime(2020,5,2,12,48)b=datetime(2020,5,2,10,18)output=CompareVariables.deep_compare(a,b,date_only=True)print(output)Output>>>Truea='2020-05-02 12:48'b='2020-05-02'output=CompareVariables.deep_compare(a,b,date_only=True)print(output)Output>>>TrueCommunicationIf you find a bug, open an issue.
If you have a feature request, open an issue.
If you want to contribute, submit a pull request.