0

I'm new to python and I'm working on a little writing in CSV project but every time that I run it it will delete my last data and write a new one this is the code

with open('data.csv', 'w', newline='')as f:
    User_new_pass = input('enter your new password: ').strip()
    User_new_id = ' ' + input('enter your new user name: ').strip()
    User_new_info = [User_new_pass, User_new_id]
    linewriter = csv.writer(f)
    linewriter.writerow(User_new_info)
Satou
  • 11
  • 3

1 Answers1

0

If you want to append to the file, you should change the mode in the open() function:

with open('data.csv', 'a', newline='')as f:
    # your code

a - Open file in append mode. If file does not exist, it creates a new file.

w - This Mode Opens file for writing. If file does not exist, it creates a new file. If file exists it truncates the file.

Gabio
  • 9,126
  • 3
  • 12
  • 32