deepdiff
deepdiff copied to clipboard
Show only the diff for larger texts in diff.pretty()
I have some keys in my dicts with values coming from larger text files, if I change only one word and use the diff.pretty() it shows the whole old text and the whole new text. I would like to have a parameter to show only the diff.
If I just print(diff) it shows to me that there is a diff parameter inside the values_changed. So I guess that is possible to add this new parameter to diff.pretty() something like diff.pretty(show_diff=True) and if diff is present it will show only the diff, if not it will use the default.
If you know another way that I can achieve this, please let me know
I was able to get this doing that:
def pretty_print_diff(diff):
type_t1 = get_type(diff.t1).__name__
type_t2 = get_type(diff.t2).__name__
val_t1 = '"{}"'.format(str(diff.t1)) if type_t1 == "str" else str(diff.t1)
val_t2 = '"{}"'.format(str(diff.t2)) if type_t2 == "str" else str(diff.t2)
diff_path = diff.path(root='root')
# I added it
if(diff.additional):
diff = diff.additional['diff']
return f"Value of {diff_path} changed. Check the diff:\n{diff}"
####
return PRETTY_FORM_TEXTS.get(diff.report_type, "").format(
diff_path=diff_path,
type_t1=type_t1,
type_t2=type_t2,
val_t1=val_t1,
val_t2=val_t2)
Ok I think we can introduce the verbose_level parameter to the pretty print too.