import json with open( ''' d:/python/爬虫/txt文件/豆瓣电影top_250.txt ''' , ' r ' ,encoding= ' utf-8 ' ) as f: fieldnames = ''' ['index','name','DaA','score','quote'] ''' items = f.readlines() content = [] for item in items: content.append( ''' eval(item.strip()) ''' ) with open( ''' d:/python/爬虫/txt文件/豆瓣电影top_250.csv ''' , ' a ' ,encoding= ' utf-8 ' ,newline= '' ) as ff: writer =csv.DictWriter(ff,fieldnames= fieldnames) writer.writeheader() writer.writerows(content)