Pycharm:获取UnicodeDecodeError:'ascii'编解码器无法解码位置0的字节0xe0:序数不在范围内(128)

时间:2018-09-18 07:16:35

标签: python python-3.x macos pycharm

当我在终端上运行时,我的代码运行没有错误,但是在pycharm上运行时却产生了以下错误

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

当在pycharm的终端上运行时,我也收到以下错误消息-

Traceback (most recent call last):
 File "/Users/swastik/Downloads/Hindi_SentiWordNet/abhi.py", line 19, 
in <module>
 di.write(str(i))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2- 
5: ordinal not in range(128)

相同的代码在我的MAC OS终端上运行时没有任何错误,并且在ubuntu 16.04上运行时,它运行正常。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
with open('annot.txt',encoding='utf-8') as h:
    an = h.readlines()
with open('MOD_HN_POS.txt',encoding='utf-8') as n:
    non = n.readlines()
anno = []
for i in an:
   anno.append(i.strip())
diff = {}
for i in non:
   if i.strip() not in anno:
      diff[i] = 0
di = open('diffpos.txt', 'w')
for i in diff.items():
   di.write(str(i))
di.close()

如何在pycharm中更正它?

0 个答案:

没有答案