今天我在用“JetBrains PyCharm”打开一个文件的时候,提示了一个“File was loaded in the wrong encoding:'UTF-8' ”错误,这个错误的意思是说:文件加载的编码错误:'UTF-8'。
解决办法
其实解决方法非常的简单,只需要改文件的编码即可!例如:UTF-8 可以修改为 GBK。
下面讲的方法适合很多的编辑器,也适合很的项目因导入出现的问题;不要仅仅只是局限于本文所遇到的python编辑器。
1、点击编辑器提示的“Reload in another encoding(重新加载另一种编码)”;
3、弹出来一个“The encoding you've chosen(‘GBK’)may change the contents of 'data.pk1'.Do you want to reload the file from disk or convert the text and save in the new encoding?(您选择的编码('GBK')可能会更改'data.pk1'的内容。是否要从磁盘重新加载文件或转换文本并保存为新编码?)”提示框,只需要点击“Convert”按钮即可!
4、会弹出来一个“Please do not convert to 'GBK', Encoding 'GBK' does not support some characters from the text。(请不要转换为'GBK',编码'GBK'不支持文本中的某些字符。)”提示框,只需要点击“Convert anyway”按钮即可!
第四步的时候需要注意,出现“GBK不支持某此字符”的时候,我们完全可以按照相同的方法再转成适合的编码即可!例如:转UTF-8。大家只需要明白这个原理即可!