文件换行
ReadFile = [] User_Choice = int(input("请输入staff_id号:")) with open("Information","r",encoding="utf8") as read_file,open("NewInformation","w+",encoding="utf8") as write_file: for line in read_file: ReadFile.append(line.strip().split(",")) for each_line in ReadFile: if User_Choice == int(each_line[0]): ReadFile.remove(ReadFile[User_Choice]) for new_line in ReadFile: write_file.write(','.join(new_line).strip("")) write_file.write("\n") #写入这行,可使文件换行 os.remove("Information") os.rename("NewInformation","Information")
天天向上,空杯心态。