时间:2022-05-05 10:20:45 | 栏目:Python代码 | 点击:次
这个行号真的很烦噶 试着写一个py去掉
def second_of_str
分割,取分隔符右边的元素返回一个列表def move
传入文件路径,读取每行,列表存储,调用 second_of_str分割后的存入新列表def second_of_str(str,splitsymbol): s = str.split(splitsymbol,1) # 分隔符右边的元素 # if len(s) == 1: # return [] return s[1] def move(file_path, new_file_path): with open(file_path,encoding='utf-8') as f: content = f.read().splitlines() # for line in content: # print(line) new_content = [] for line in content: new_line = second_of_str(line,'.') # 去掉后的每行加入新列表 new_content.append(new_line) for line in new_content: print(line) f1 = open(new_file_path,encoding='utf-8',mode = 'w') for line in new_content: f1.writelines(line) f1.writelines(["\n"]) f1.close() return new_content if __name__ == '__main__': f = move('1.txt','2.txt')
完成啦,成果~