最近重新裝了一下pycharm出現了很多問題 素材///心塞塞,
如果讓你重新來過
你還亂刪註冊表不
言歸正傳
如果python文件中有中文字符,且未聲明編碼,就會出現報錯信息: File “encode.py”, line 1SyntaxError: Non-ASCII character ‘\xe7’ in file encode.py on line 1, but no encoding declared; see //…python…/dev/peps/pep-0263/ for details for details
根據錯誤提示,我們在python官網得到如下幫助信息:
Python will default to ASCII as standard encoding if no other encoding hints are given.
翻譯:如果沒有其他編碼提示,Python將默認爲ASCII作爲標準編碼。
To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file
翻譯:要定義源代碼編碼,必須在源文件中第一行或第二行放置一個魔術註釋(就像這樣)
所以,按照幫助文檔的提示以及例子,我們在Python文件中加入一個編碼聲明:
# coding=utf-8
在文檔開頭就好啦,問題解決√