File size: 984 Bytes
aec8354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pandas as pd
import csv

def save_csv_info(filepath, ID, output):
    # 读取CSV文件
    # with open(f'./database_name.csv', 'r', encoding='utf-8') as file:
    with open(filepath, 'r', encoding='utf-8') as file:
        
        # 创建CSV读取器
        reader = csv.reader(file)

        # 将内容存储到列表中
        rows = []
        for row in reader:
            rows.append(row)

    # 添加新行
    # new_row = ['New Data 1', 'New Data 2'] # 新行的数据
    new_row = [ID, output] # 新行的数据
    rows.append(new_row)

    # 写入CSV文件
    # with open('./database_name.csv', 'w', newline='', encoding='utf-8') as file:
    with open(filepath, 'w', newline='', encoding='utf-8') as file:
        # 创建CSV写入器
        writer = csv.writer(file)
        # 写入所有行
        writer.writerows(rows)
    
    # close the file to save the data. 
    file.close()

    # return None

# save_csv_info('./summary.csv', '123', 'text')