鍍金池/ 問(wèn)答/Python/ python 在寫(xiě)入csv 的時(shí)候 多了個(gè)雙引號(hào)

python 在寫(xiě)入csv 的時(shí)候 多了個(gè)雙引號(hào)

csv.writer(f, dialect="excel").writerow(               [{"found_year":found_year,"jg_type":jg_type,"area":area,"source_gw_link":source_gw_link,"jianjie":jianjie,"lianxi":lianxi},{"company_news":company_news}, {"name":name,"sex":sex,"company":company,"position":position,"role" :role, "edu_experience":edu_experience,"work_experience": json.dumps(OrderedDict(sorted(work_experience.items()))).encode('utf-8').decode('unicode_escape')}, {"lingyu":lingyu,"jiguan":jiguan,"lunci":lunci,"jieduan":jieduan,"jieshao":jieshao,"money_type":money_type,"touzianlie":json.dumps(OrderedDict (sorted(tzanli.items()))).encode('utf-8').decode('unicode_escape')},{"person_news":json.dumps(OrderedDict(sorted(person_news.items()))).encode('utf-8').decode('unicode_escape')}])

這段信息 其中的一段 我打印屏幕上 是這樣的'news_date': '2018.7.17',后來(lái)就插入csv 后就變成這樣了
""news_date"": ""2018.7.26""

回答
編輯回答
尤禮
尷尬,就沒(méi)看到news_date,請(qǐng)把數(shù)據(jù)上傳的全一點(diǎn)。
2018年2月7日 11:19
編輯回答
誮惜顏

在你的源代碼中看不見(jiàn)'news_date'這個(gè)鍵值。解決方法就是在導(dǎo)出csv前你把'news_date' '2018.7.17'兩邊的單引號(hào)去掉就好了。這個(gè)引號(hào)不是表示字符串,而是字符串本身的一部分。

你自己也可以試一下,如果變量自帶引號(hào),打印就會(huì)把引號(hào)打印出來(lái),比如

s = "test"
print(s) # 輸出沒(méi)有引號(hào)的test
s = "'test'"
print(s) # 輸出有引號(hào)的'test'
2017年4月1日 09:25