python csv 使用

http://zetcode.com/python/csv/

https://docs.python.org/3/library/csv.html

 

# import json

# with open(
#         'C:\\Users\\23141\\Desktop\\2020-01-21__江苏安靠智能输电工程科技股份有限公司__300617__安靠智电__2019年__年度报告.txt',
#         'r',
#         encoding="utf8") as f:
#     with open('2020-01-21__江苏安靠智能输电工程科技股份有限公司__300617__安靠智电__2019年__年度报告.txt',
#               'w',
#               encoding="utf8") as out:
#         line = f.readline()
#         while line:
#             print(line)
#             data = json.loads(line)
#             if data['type'] == 'text':
#                 print(data['inside'])
#                 out.write(data['inside'])
#             line = f.readline()
# print(list(range(1, 10)))
import csv
import json

header = ['影院', '编码', '影厅名称', '放映日期', '放映时间', '价格']

with open("poet.csv", "w", encoding="utf-8", newline='') as out:
    writer = csv.writer(out)
    writer.writerow(header)
    with open("d:\\software\\0810.csv", encoding="utf8") as f:
        reader = csv.reader(f, escapechar='\\')
        for row in reader:
            print(row[5])
            price = json.loads(row[5])[0]
            print('price:', price)
            row[5] = price['settlePrice']
            print(row)
            writer.writerow(row)
posted @ 2019-12-06 11:56  java渣渣  阅读(139)  评论(0编辑  收藏  举报