I'm trying to use this function to return two lists using the class dircmp
from the filecmp
module.
I need to use the lists generated in multiple different parts throughout my code, for now I've been doing this by making the list a global variable.
I would like to know if there is a solution to return both lists that have fully appended after the function is done recursing through sub-directories. This way I don't need to keep creating global variables for every function through my code.
For reference the functions recurse in the same way, but they track a different set of data, for example same_files which need to split into same_leftpath_list
and same_rightpath_list
.
diff_leftpath_list = []
diff_rightpath_list = []
def print_diff_files(dcmp):
for name in dcmp.diff_files:
print("[Differing File] '%s' found in %s and %s" % (name, dcmp.left,
dcmp.right))
diff_leftpath = os.path.join(dcmp.left, name)
diff_rightpath = os.path.join(dcmp.right, name)
diff_leftpath_list.append(diff_leftpath)
diff_rightpath_list.append(diff_rightpath)
for sub_dcmp in dcmp.subdirs.values():
print_diff_files(sub_dcmp)
print_diff_files(dcmp)
print diff_leftpath_list