當我嘗試運行此代碼:Pycharm和代碼UTF-8
with open('scraped.csv', 'w') as dump:
writer = csv.writer(dump, delimiter='ę', escapechar='\\',quoting=csv.QUOTE_NONE)
writer.writerow(('author', 'ups', 'downs',
'score', 'sub_name', 'replys',
'created_utc', 'pulled down at'))
在PyCharm
,我收到以下錯誤
File ..., line 38, in <module>
'created_utc', 'pulled down at'))
UnicodeEncodeError: 'ascii' codec can't encode character '\u0119' in position 6: ordinal not in range(128)
是PyCharm不能支持UTF-8文件?或者我錯過了某個地方的設置。相同的文件建立在Sublime中。
我相信'csv'模塊指定文件必須以二進制模式打開。 –
@MarkRansom:在Python 3中,它應該是一個帶'newline ='''參數的文本模式。 – jfs