I want to combine combine fields from an input .csv file for output to a .csv file, and some contain commas. Here is my code, simplified
outfile = open('output.csv', 'w')
#these values are made up for this example; normally they would be read from
#a csv and passed to the following 'combine()' function
a = "John"
b = ",Jr."
def combine(a, b):
if a == "":
pass #don't write anything if the field is empty
else:
outfile.write(a)
if b =="":
pass
else:
outfile.write(b)
If b starts with a comma, how do I make the output "John, Jr." ? I have tried using the csv.writer writerow() but it puts a comma delimiter between each character. I have tried defining an escapechar but it just outputs "John \" , "Jr." Suggestions?