36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
def process_lines(lines):
|
|
result = []
|
|
i = 0
|
|
while i < len(lines):
|
|
current_line = lines[i].strip()
|
|
if i > 0 and current_line == '(value)':
|
|
# 如果当前行只包含 (self),将其合并到上一行
|
|
prev_line = result.pop()
|
|
new_line = prev_line.rstrip() + " (value)"
|
|
result.append(new_line + '\n')
|
|
else:
|
|
result.append(lines[i])
|
|
i += 1
|
|
return result
|
|
|
|
|
|
def process_file(input_file_path, output_file_path):
|
|
try:
|
|
with open(input_file_path, 'r', encoding='utf-8') as file:
|
|
lines = file.readlines()
|
|
processed_lines = process_lines(lines)
|
|
with open(output_file_path, 'w', encoding='utf-8') as output_file:
|
|
output_file.writelines(processed_lines)
|
|
print(f"处理完成,结果已保存到 {output_file_path}")
|
|
except FileNotFoundError:
|
|
print(f"未找到输入文件: {input_file_path}")
|
|
|
|
|
|
# 输入文件路径
|
|
input_file = 'a00006.txt-merge.txt-new.txt'
|
|
# 输出文件路径
|
|
output_file = 'output.txt'
|
|
|
|
process_file(input_file, output_file)
|
|
|