You can download this code by clicking the button below.
This code is now available for download.
Reads a CSV file and converts its content to a list of dictionaries.
Technology Stack : csv, built-in library
Code Type : Function
Code Difficulty : Intermediate
import csv
import json
import random
import re
import sys
import time
def read_csv_to_dict(file_path):
"""
读取CSV文件并将内容转换为字典列表。
:param file_path: CSV文件路径
:return: 字典列表
"""
with open(file_path, mode='r', encoding='utf-8') as file:
reader = csv.DictReader(file)
return list(reader)