Python Forum
Multiple entries into a csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple entries into a csv file
#1
The following code allows me to add only 2 sets of data to the csv file. The second bit of code continually overwrites the last 3 entries that I make. Please can anyone help me with this problem, all I wish to do is to add multiple entries without anything being overwritten?

I have copied the code below;

import csv

with open('users2.csv','a') as f:# 'a' will add to the existing csv file.
    #f.write()#f.write('user,pword,day')
    x=input("User name? ")
    y=input("Password? ")
    z=input("Day? ")
with open('users2.csv','a',newline='') as f:
    writer=open('users2.csv')
    writer=csv.writer(f)
    writer.writerow([])
    writer.writerow([x,y,z])
    response=input("Would you like another entry; Yes or No? ")
    while response == 'Yes':
        a=input("User name? ")
        b=input("Password? ")
        c=input("Day? ")
        response=input("Would you like another entry; Yes or No? ")             
    else:
            response=input("Return to end...")         
with open('users2.csv','a') as f:
    writer=csv.writer(f)
    writer.writerow([a,b,c])
Reply


Messages In This Thread
Multiple entries into a csv file - by SatansClaw - Jun-11-2019, 10:24 AM
RE: Multiple entries into a csv file - by stullis - Jun-13-2019, 07:06 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020