reload(sys)
sys.setdefaultencoding("utf-8")
f = open('.\\24.novel.txt','rb')
str = f.read().decode('utf-8')
f.close()
Found by Baidu
Python 3 string encodes Unicode by default, so sys. Set default encoding doesn't exist
So just delete it
Similar Posts:
- UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-1:
- Python solves the problem of NameError: name ‘reload’ is not defined
- Error reporting and resolution of Python 3 using binascii method
- TypeError: the JSON object must be str, not ‘bytes’
- attributeerror: ‘str’ object has no attribute ‘decode’
- [Solved] Python Error: UnicodeDecodeError: ‘gb2312’ codec can’t decode byte 0xa4 in position… : illegal multibyte sequence
- Python Open File SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in …
- [Solved] TypeError: string indices must be integers, not str
- [Solved] Python Numpy Data load error: Unicode error: unpicking a python object failed: Unicode decodeerror
- Install CDH6.2 agent error [How to Solve]