文件换行

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")

  

posted @ 2016-11-04 00:50  梦轻尘  阅读(175)  评论(0编辑  收藏  举报