入力.csvファイルの結合フィールドを結合して.csvファイルに出力したいのですが、一部にはコンマが含まれています。これが私のコードです、簡略化されています
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)
bがコンマで始まる場合、出力「John、Jr」を作成するにはどうすればよいですか。?csv.writer writerow()を使用してみましたが、各文字の間にコンマ区切り文字が挿入されています。を定義しようとしましたescapechar
が、「John \ "、"Jr。」が出力されます。提案?