New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encoding problem: coding:gbk cause syntaxError #79321
Comments
OS 名称: Microsoft Windows 10 专业版 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 |
If I understand your question correctly, you should save the file(the one contain Chinese chars) with GBK encoding using your editor. Otherwise, your editor would save it using the default encoding which led to python can't decode it correctly. |
Let me give an explanation. D:\>encoding_problem_gbk.py If remove the comment line, run as expected. |
Thank you, Lin. Can you reproduce on your machine, I guess it is related to terminal encoding or text file ending. However, I can't reproduce on macOS. |
Yes, I can reproduce on my Windows 10 (Simplfied Chinese). |
this problem not exist on macOS. Windows10x64 Python 3.7.0 (v3.7.0:1bf9cc5093 script have no problem with 15 blank lines. |
I'm sorry for my english. |
I'm afraid you'll have to use English in this forum so that all current and future readers have the best chance of understanding the situation. Thank you very much for making the effort this far. If anyone on this issue knows of a Chinese-language forum where this issue could explored before coming back here, please say so. Otherwise I'll ask around on Twitter etc. to see what's available |
It's fine @anmikf, keep practice :D. Let's recap what happened: Run encoding_problem_gbk.py on Windows10 using Python 3.7.0 will cause "SyntaxError: encoding problem: gbk". But it will run as expected if
|
Yes, seems like we should be opening the file in binary mode, though I haven't tried it. The CRT's interpretation of text mode really isn't compatible with Python's own interpretation of text mode, and chaining them makes even less sense. |
I can not reproduce this issue on my Debian9. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: