下面的代码是我到目前为止所拥有的。当它写入 .csv 时,它会覆盖我之前在文件中写入的内容。我怎样才能以不会删除我以前的文本的方式写入文件。(我的代码的目标是让一个人输入他们的名字并让程序记住他们)
def main(src):
try:
input_file = open(src, "r")
except IOError as error:
print("Error: Cannot open '" + src + "' for processing.")
print("Welcome to Learner!")
print("What is your name? ")
name = input()
for line in input_file:
w = line.split(",")
for x in w:
if x.lower() == name.lower():
print("I remember you "+ name.upper())
else:
print("NO")
a = open("learner.csv", "w")
a.write(name)
a.close()
break
if __name__ == "__main__":
main("learner.csv")