29 lines
968 B
Python
29 lines
968 B
Python
def process_file(input_file_path, output_file_path):
|
|
with open(input_file_path, 'r', encoding='utf-8') as input_file:
|
|
lines = input_file.readlines()
|
|
|
|
processed_lines = []
|
|
i = 0
|
|
while i < len(lines):
|
|
line = lines[i].strip()
|
|
if line == 'def':
|
|
# 如果当前行只包含 'def'
|
|
next_line = lines[i + 1].lstrip() if i + 1 < len(lines) else ''
|
|
# 将下一行内容缩进并和 'def' 保持在同一行
|
|
new_line = f"def {next_line}"
|
|
processed_lines.append(new_line)
|
|
i += 2 # 跳过下一行
|
|
else:
|
|
processed_lines.append(lines[i])
|
|
i += 1
|
|
|
|
with open(output_file_path, 'w', encoding='utf-8') as output_file:
|
|
output_file.writelines(processed_lines)
|
|
|
|
# 输入文件路径
|
|
input_file_path = 'a00006.txt-merge.txt-new.txt'
|
|
# 输出文件路径
|
|
output_file_path = 'output.txt'
|
|
|
|
process_file(input_file_path, output_file_path)
|