无法在文本文件的新行中添加记录

时间:2018-11-07 20:35:50

标签: python

我试图让用户将记录添加到我创建的文本文件中。该记录已经添加了一些记录。

if (user.getIdentifiantAAA() != null)

问题是,当我第一次添加一条记录时,它将完美运行,创建的记录将在新行上,但是如果我重新运行代码并添加一条新记录,那么它将只连接到最后的记录,它将忽略def add_new_employee(): with open("records.txt", "a") as storing_records: storing_records.write(input("\n" + "please enter your details in the following format followed by commas between each field: User ID, Name, Age, Position, Salary, Years employed: "))

1 个答案:

答案 0 :(得分:1)

如果您首先创建一个变量,然后将输入写在单独的一行中怎么办? 我还在输入后添加了换行符。曾经那样对我有用。

def add_new_employee():  
       with open("records.txt", "a") as storing_records:
           user_input = input("Please enter your details....")
           storing_records.write(user_input + "\n")