我有一个 CSV 文件,我正在尝试采用以下格式:
Blocklist, Name
BL1, Name1
BL2, Name2
BL3, Name3
但是,我将阻止列表打印在标题下的 1 长行中。
Blocklist, Name
BL1, BL2, BL3, BL4
如上所述,我如何能够将其拆分为多行?到目前为止,这是我的代码
response = requests.get(url, params=params)
if response.status_code != 200:
raise ApiError(response.status_code)
print('Something went wrong')
with open('new_file.csv', 'a') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
json_data = response.json()
vt_result = []
for k, v in json_data['scans'].items():
if not v.get("detected", False):
vt_result.append(k)
csv_writer.writerow(vt_result)
我试过使用
for k, v in json_data['scans'].items():
if not v.get("detected", False):
#vt_result.append(k)
csv_writer.writerow(k)
但这会在所有字符之间打印逗号。例如,N,a,m,e,1
答案 0 :(得分:0)
看起来 csv
正在等待一个 dict。更改为以下内容解决了我的问题。
for k, v in json_data['scans'].items():
if not v.get("detected", False):
#vt_result.append(k)
csv_writer.writerow([k])