admin管理员组文章数量:1024582
My file setting in VS Code is set to UTF-8 (default) rendering. If I run my line via Shift+Enter, the python Native REPL opens but i get the wrong encoding as i show below. However, If i run using the interactive window (jupyter) or via the terminal I get the correct rendering.
example code:
print('Accented letters: á, é, í, ó, ú, ü, ñ')
I get this wrong output as follows:
Accented letters: á, é, Ã, ó, ú, ü, ñ
My file setting in VS Code is set to UTF-8 (default) rendering. If I run my line via Shift+Enter, the python Native REPL opens but i get the wrong encoding as i show below. However, If i run using the interactive window (jupyter) or via the terminal I get the correct rendering.
example code:
print('Accented letters: á, é, í, ó, ú, ü, ñ')
I get this wrong output as follows:
Accented letters: á, é, Ã, ó, ú, ü, ñ
Share
Improve this question
edited Nov 20, 2024 at 23:15
Ash
asked Nov 18, 2024 at 20:18
AshAsh
315 bronze badges
6
|
Show 1 more comment
1 Answer
Reset to default 0set the REPL encoding to utf-8?
The code below works for me:
print(('Accented letters: á, é, í, ó, ú, ü, ñ').encode('cp1252').decode('utf-8'))
My file setting in VS Code is set to UTF-8 (default) rendering. If I run my line via Shift+Enter, the python Native REPL opens but i get the wrong encoding as i show below. However, If i run using the interactive window (jupyter) or via the terminal I get the correct rendering.
example code:
print('Accented letters: á, é, í, ó, ú, ü, ñ')
I get this wrong output as follows:
Accented letters: á, é, Ã, ó, ú, ü, ñ
My file setting in VS Code is set to UTF-8 (default) rendering. If I run my line via Shift+Enter, the python Native REPL opens but i get the wrong encoding as i show below. However, If i run using the interactive window (jupyter) or via the terminal I get the correct rendering.
example code:
print('Accented letters: á, é, í, ó, ú, ü, ñ')
I get this wrong output as follows:
Accented letters: á, é, Ã, ó, ú, ü, ñ
Share
Improve this question
edited Nov 20, 2024 at 23:15
Ash
asked Nov 18, 2024 at 20:18
AshAsh
315 bronze badges
6
-
I can't reproduce this; both
.ipynb
files and the# %%
cell notation are working fine for me. Can you provide more debugging steps? – Anerdw Commented Nov 19, 2024 at 0:08 - Not sure how i can oprovide more details. i'm running the code snippets using shift enter, which opens the vscode interactive python repl. String outputs there are scrambled, obviously encoding problem. – Ash Commented Nov 19, 2024 at 4:17
- Ok so aparently i'm running lines in python REPL via shift+enter. I If you right click at a line, you can select run python-> run line in PYthon REPL (which looks exatcly like the interactive window if you right click then select run in interactive window). If i run in interactive window, the output is encoded correctly. But what is the difference between the interactive window and the python REPL? they both look and behave the same apart from the encoding problem. and why do i get an enconding problem running via Python REPL? – Ash Commented Nov 19, 2024 at 4:51
- Consider writing an edit to address those issues. Don't write a big "EDIT:" section, but do update your questions with those details since they'll be relevant to any good answer. – Anerdw Commented Nov 19, 2024 at 5:16
- I'm assuming you are a Windows user? It isn't a question of whether the Python REPL and the IPython interactive window are doing anything different. The question is what encoding the console/terminal that REPL is running in. You are using utf-8 in Python but your IO boundary in the terminal is not UTF-8. – Andj Commented Nov 19, 2024 at 20:30
1 Answer
Reset to default 0set the REPL encoding to utf-8?
The code below works for me:
print(('Accented letters: á, é, í, ó, ú, ü, ñ').encode('cp1252').decode('utf-8'))
本文标签: Why does VS Codes39s Python REPL window output letters with wrong encodingStack Overflow
版权声明:本文标题:Why does VS Codes's Python REPL window output letters with wrong encoding? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745596551a2158205.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.ipynb
files and the# %%
cell notation are working fine for me. Can you provide more debugging steps? – Anerdw Commented Nov 19, 2024 at 0:08