请教Python写入CSV文件的问题
想将数据保存到csv文件中,碰到个问题,好像在写入过程中碰到了什么特殊字符(好像是这个“•”),运行到写入“花开尘埃•蔓生苍华:民国才女经典书系”这段时,就自动终止写入了,求教高手看看问题在什么地方,怎么解决,谢谢。测试代码如下:
程序代码:
#!/usr/bin/env python # -*- encoding: utf-8 -*- import csv def write_data(info): with open('test.csv','a',newline='') as f: filed = ['书名','百度网盘链接','提取码'] writer = csv.DictWriter(f,fieldnames=filed) writer.writeheader() try: writer.writerows(info) except: pass info = [ {'书名': '凯恩舰哗变', '提取码': 'pnus', '百度网盘链接': 'https://pan.baidu.com/s/1U_4lhaAfx6_BqJYCTml3wQ'}, {'书名': '战争风云', '提取码': 'mfa9', '百度网盘链接': 'https://pan.baidu.com/s/1aQgdhf9Tw8-9o7aAY4mnkg'}, {'书名': '走近费曼丛书(套装共6册)', '提取码': '6gts', '百度网盘链接': 'https://pan.baidu.com/s/1gKgiqRTgUFJyGIw9podUCQ'}, {'书名': '花开尘埃•蔓生苍华:民国才女经典书系', '提取码': 'aycv', '百度网盘链接': 'https://pan.baidu.com/s/1vXEpeK8C4vR3xDXLq4r1Lg'}, {'书名': '数学之美', '提取码': '7inb', '百度网盘链接': 'https://pan.baidu.com/s/1SdfZy7kZBIw_lmcsXOTOQw'}, {'书名': '向着光亮那方:谁的青春不迷茫系列', '提取码': 'ys3r', '百度网盘链接': 'https://pan.baidu.com/s/1ZQ6eUYmUNi0khhBRS-ILaQ'}, {'书名': '向着大地和天空,凡人和诸神:海德格尔导读', '提取码': 'dujx', '百度网盘链接': 'https://pan.baidu.com/s/1M4OLu45R2PsMzNOZTmfNDg'}, {'书名': '中国传世古典TOP50大书系', '提取码': '3usd', '百度网盘链接': 'https://pan.baidu.com/s/1lsIeYDc3RZ3rCyNbdgu0ZQ'}, {'书名': '读者200期合订本(1981~1997)', '提取码': 'rk3b', '百度网盘链接': 'https://pan.baidu.com/s/1VBYpZUjTgllGutCBFDZ0wg'}, {'书名': '道德经全鉴(典藏版)', '提取码': 'pjje', '百度网盘链接': 'https://pan.baidu.com/s/1SA3XfMC957BjnDshuyAu9A'}, {'书名': '最忆西窗同剪烛:纳兰容若词全集', '提取码': '7v57', '百度网盘链接': 'https://pan.baidu.com/s/1NURvyhZODk42xb6oa1ST-Q'}, {'书名': '第九届茅盾文学奖获奖作品全集', '提取码': 'jmgx', '百度网盘链接': 'https://pan.baidu.com/s/1Hsb2EUGjih5uhhvlUpmotg'}, {'书名': '钱穆作品集7本', '提取码': 'gcm4', '百度网盘链接': 'https://pan.baidu.com/s/1BSVcAeIoy29ni_OH2PKvQg'}, {'书名': '吕思勉文集9本', '提取码': 'qt4x', '百度网盘链接': 'https://pan.baidu.com/s/1X-i8PX7AajbRWlVMare5lg'} ] if __name__ == "__main__": write_data(info)