我正在编写具有以下功能的 CSV 文件:
import csv
import os
import aiofiles
async def write_extract_file(output_filename: str, csv_list: list):
"""
Write the extracted content into the file
"""
try:
async with aiofiles.open(output_filename, "w+") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=columns.keys())
writer.writeheader()
writer.writerows(csv_list)
except FileNotFoundError:
print("Output file not present", output_filename)
print("Current dir: ", os.getcwd())
raise FileNotFoundError
但是,由于不允许等待writerows方法,因此没有行被写入 CSV 文件。
如何解决这个问题?有什么解决方法吗?
谢谢。完整的代码可以在这里
慕码人8056858
摇曳的蔷薇
天涯尽头无女友
相关分类