I have a csv file called doctors.csv containing
1,John,Smith,Internal Med
2,Jone,Smith,Pediatrics
3,George,Carlos,Cardiology
I have code that is going to replace just the first name of one row. It asks for which row they would like to replace and then asks for what they want to replace it with
file = open("doctors.csv", "r")
x= 0
tmplist = []
for row in file:
tmplist.append(row)
file.close
for row in tmplist:
print (x,row)
x = x+1
rowchange = int(input("Enter the row number to change: "))
makechange= input(str("What is the new first name: "))
file.close()
with open("doctors.csv","r") as doctorcsv:
r = csv.reader(doctorcsv)
lines = list(r)
print (lines)
lines[rowchange][1]=makechange
print(lines)
writer = csv.writer(open('doctors.csv', 'w'))
writer.writerows(lines)
here's what I have but it introduces newlines into the csv file which would cause issues for other parts of my system like this.
1,John,Smith,Internal Med
2,Jone,Smith,Pediatrics
3,George,Carlos,Cardiology
How can I delete the newlines in the csv file?