It unconditionally terminates your Python interpreter. Don't exitĪvoid calling sys.exit() at all costs. The Python 3.x interpreter will ignore this import, because the future is now. In Python 2.7, you can add at the top of your script:Īnd the Python 2.7 interpreter will then allow you to use Python 3.x style print() statements. In these cases, it is much better to write code which will run equally well in both interpreters. However, there may be times when you must use Python 2.7. I'm going to assume this was some sort of copy-paste error (but that would be very odd since it was in the middle of the code!). Print "Compare dirs %s and %s" % (dir_a, dir_b)Ĭompare_dir_trees(dir_a, dir_b, compare_file_data, file_to_save_results)įor common_dir in dirs_cmp.common_dir: fails, because dirs_cmp does not have a common_dir. New_dir2 = os.path.join(dir2, common_dir)Ĭompare_dir_trees(new_dir1, new_dir2, compare_file_data, file_to_save_results) New_dir1 = os.path.join(dir1, common_dir) Show_diff_in_files(dir1, dirs_cmp.diff_files, file_to_save_results) If compare_file_data and dirs_cmp.diff_files: Show_diff_in_dir(dir2, dirs_cmp.right_only, file_to_save_results) Show_diff_in_dir(dir1, dirs_cmp.left_only, file_to_save_results) Msg = "different files in %s : %s " % (dir_name, diff_files)ĭef compare_dir_trees(dir1, dir2, compare_file_data, file_to_save_results): Msg = "files or subdirs only in %s : %s " % (dir_name, list_diff)ĭef show_diff_in_files(dir_name, diff_files, file_to_save_results): Print "-a : also compare data inside files"ĭef show_diff_in_dir(dir_name, list_diff, file_to_save_results): Print "dir_1 and dir_2 : directories to compare" Note: this is in Python 2.7, and I don't have access to argparse. a to also compare the content of the files.It compares two directories, showing all files that are in one and not in the other. Coming from another language than Python, I would like to see if my code is "pythonic" enough and follows good practices.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |