我想组合输入 .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." 建议?