AI - 处理prompt前置(一)

使用 prettytable 格式化处理 csv 数据


'''
Author: “ifredom” [email protected]
Date: 2023-07-21 23:46:13
LastEditors: “ifredom” [email protected]
LastEditTime: 2023-07-21 23:51:35
'''
from prettytable import PrettyTable

# 传入的 name、age、country 相当于表头
tb = PrettyTable(["name", "age", "country"])
# 调用 add_row 添加行记录
tb.add_row(["Jack Morrison", 49, "America"])
tb.add_row(["Shimada Genji", 35, "Japan"])
tb.add_row(["Shimada Hanzo", 38, "Japan"])
tb.add_row(["Angela Ziegler", 37, "Switzerland"])

print(tb)


with open('data.csv', 'w') as file:
    file.write(tb.get_csv_string())

猜你喜欢

转载自blog.csdn.net/win7583362/article/details/131862111
AI