0

I'm using PyCharm to run code:

exec(open('file.py').read())

while running some file I got:

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 2655: illegal multibyte sequence

Any friend can help?

William
  • 3,724
  • 9
  • 43
  • 76
  • If the file does not contain valid unicode, it should be opened with binary indicator. – guidot Apr 30 '20 at 14:11
  • Thanks,I have this:# -*- coding: utf-8 -*- – William Apr 30 '20 at 14:38
  • The question is not, what the file states it is, but how the editor was configured, which wrote it. These seem not to match. An `\xA7` should be easy to find... – guidot Apr 30 '20 at 14:46
  • In text mode, if encoding is not specified the encoding used is platform dependent: `locale.getpreferredencoding(False)` is called to get the current locale encoding. Use `open('file.py', encoding='utf-8-sig')` – JosefZ Jun 02 '20 at 20:07

0 Answers0