-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch_21.py
More file actions
17 lines (14 loc) · 1015 Bytes
/
Copy pathscratch_21.py
File metadata and controls
17 lines (14 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def copy_unique_lines(file1_path, file2_path):
with open(file1_path, 'r', encoding="utf-8") as file1:
with open(file2_path, 'r', encoding="utf-8") as file2:
# 读取第二个文件的所有行,去除每行末尾的换行符
file2_lines = {line.strip() for line in file2}
# 逐行读取第一个文件,去除每行末尾的换行符
unique_lines = [line.strip() for line in file1 if line.strip() not in file2_lines]
# 一次性打开第二个文件以追加模式,写入所有不重复的行
with open(file2_path, 'a', encoding="utf-8") as file2:
for line in unique_lines:
file2.write(line + '\n')
# 调用函数,传入两个文件的路径
copy_unique_lines(r'T:\桌面\celestial_artifacts-1.18\celestial_artifacts-1.18\src\main\resources\assets\celestial_artifacts\lang\1.json',
r'T:\桌面\celestial_artifacts-1.18\celestial_artifacts-1.18\src\main\resources\assets\celestial_artifacts\lang\zh_cn.json')