bash
from pathlib import Path
LIST_FILE = Path(r"D:\1_code\dev_tmp\list.txt")
OUTPUT_FILE = Path(r"D:\1_code\dev_tmp\list_output.txt")
def main() -> None:
text = LIST_FILE.read_text(encoding="utf-8")
lines = text.splitlines()
if not lines:
raise SystemExit(f"文件为空: {LIST_FILE}")
formatted = []
for line in lines:
line = line.rstrip()
if line.startswith("'") and line.endswith("',"):
formatted.append(line)
else:
formatted.append(f"'{line}',")
OUTPUT_FILE.write_text("\n".join(formatted) + "\n", encoding="utf-8")
print(f"已处理 {len(formatted)} 行,写入 {OUTPUT_FILE}")
if __name__ == "__main__":
main()
list.txt
bash
L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_0
L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_1
L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_2
L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_3
L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_4
L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_5
list_output.txt
bash
'L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_0',
'L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_1',
'L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_2',
'L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_3',
'L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_4',
'L2_bahaogongfang_off_ff_RS10X5_1_L2_denoised_rot_5',