Message374961
A potential UnicodeDecodeError could be raised when run "python -m dis" on non-utf8 encoding environment.
Assume there is a file named "a.py", and contains "print('喵')", then save with UTF8 encoding.
Run "python -m dis ./a.py", on non-UTF8 encoding environment, for example a Windows PC which default language is Chinese.
A UnicodeDecodeError raised.
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python38\lib\dis.py", line 553, in <module>
_test()
File "C:\Program Files\Python38\lib\dis.py", line 548, in _test
source = infile.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb5 in position 9: illegal multibyte sequence
That because Windows' default encoding is decided by language. Chinese use cp936(GB2312) as default encoding and can't handle UTF8 encoding.
It just need to read in "rb" mode instead of "r". |
|
Date |
User |
Action |
Args |
2020-08-06 19:52:45 | zkonge | set | recipients:
+ zkonge |
2020-08-06 19:52:45 | zkonge | set | messageid: <1596743565.22.0.770154691166.issue41497@roundup.psfhosted.org> |
2020-08-06 19:52:45 | zkonge | link | issue41497 messages |
2020-08-06 19:52:44 | zkonge | create | |
|