添加编码格式:
encoding='utf_8_sig'
def saveColumnNameToCSV(OSSPath,rowsInfo): with open(OSSPath,"w",newline='',encoding='utf_8_sig') as f: headers=["No","OSS","License","Feature","Type","Version","Encription","Modification","Comment","Homepage","License in statement ","Link to License template"] fcsv = csv.DictWriter(f,headers) fcsv.writeheader() fcsv.writerows(rowsInfo) ##rowinfos是一个list类型 ##[ {"NO":1,"OSS":2,,,,"Link to License template":3} ## {"NO":3,"OSS":4,,,,"Link to License template":5} ]
解决方法来源:
https://blog.csdn.net/anchor164/article/details/104998937