当它写入 CSV 文件时,它会将每个字母写入自己的单元格。关于如何解决这个问题的任何想法?
我正在尝试将“名称”写入它自己的单元格。
谢谢!
import json
import csv
from unidecode import unidecode
def main():
csv_writer = open_csv() #returns the functionality to write to a csv
str_data = []
with open('location') as f:
for line in f:
str_data.append(json.loads(line))
data = str_data[0]
for item in data['contacts']:
linkedin_name = unidecode(name(item))
write_to_csv(csv_writer, linkedin_name)
def name(item):
name = item['name']
return name
def open_csv():
final_csv = open('test.csv', 'wb')
csv.writer = csv.writer(final_csv)
return csv.writer
def write_to_csv(csv_writer, linkedin_name):
csv_writer.writerow(linkedin_name)
if __name__ == '__main__':
main()