功能,去掉txt.文本里的字段前的data/images/fall def remove_prefix(text, prefix): if text.startswith(prefix): return text[len(prefix):] return text input_file = "input.txt" output_file = "output.txt" prefix_to_remove = "data/images/fall"# with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8') as outfile: for line in infile: line = line.strip() # 去掉行首尾的空格和换行符 new_line = remove_prefix(line, prefix_to_remove) outfile.write(new_line + '\n') print("处理完成!")
一个对txt文件进行批量修改的python代码
最新推荐文章于 2024-04-26 10:41:32 发布