Cant print letters such as å, ä, ö in PowerShell and when I do it prints, for example, ä

huangapple go评论68阅读模式
英文:

Cant print letters such as å, ä, ö in PowerShell and when I do it prints, for example, ä

问题

我正在使用 Windows 11,使用 VS Code 编写 Python 代码,以及在执行代码时使用 PowerShell。我有一个瑞典语的文本文件,我想要打印出来,但是当我打印字母 å、ö 和 ä 时,它们打印出来的是类似于 ä 和其他奇怪字符的东西。

我已将文本文件保存为 UTF-8,并且我的 chcp 设置为 65001,这应该是通用选项,但仍然不起作用。实际上,当我将文本文件保存为 ANSI 时,它确实可以工作,但我想将其保存为 UTF-8 并使其正常工作。

英文:

I'm on Windows 11 using VS Code for the coding thing with python and using PowerShell when I execute my code. I got a text file on swedish which I want to print but when I print the letter å, ö and ä it prints them like ä and other type of strange characters.

I have saved the text file as UTF-8 and my chcp is on 65001 which should be the universal option but it still doesn't work. It does actually work when I save the text file as ANSI but I want to have it as UTF-8 and make it work.

答案1

得分: -1

Vscode 使用系统内嵌的终端,因此终端显示的字符与许多方面相关。系统语言、终端代码页、文件编码等都会影响字符的显示。任何配置不一致都可能导致字符显示不正确。

就我的机器而言,现在是系统的中文语言,代码页是437,字符显示正常。

此外,您还可以安装Code Runner,默认情况下会在输出面板中输出结果,这可能会带来正确的显示效果。

如果没有特殊要求,请不要使用Code Runner。官方扩展Python的效果更好。

配置以下的launch.json,使用“无调试运行”,结果将在DEBUG CONSOLE面板中输出。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "internalConsole",
            "justMyCode": true
        }
    ]
}
英文:

Vscode uses the integrated terminal embedded in the system, so the characters displayed by the terminal are related to many aspects. System language, terminal code page, file encoding, etc. Any configuration inconsistency may cause your characters to display incorrectly.

  • As far as my machine is concerned, it is now the system Chinese language, the code page is 437, and the characters are displayed normally.

    Cant print letters such as å, ä, ö in PowerShell and when I do it prints, for example, ä

  • In addition, you can also install Code Runner, by default it will output the result in the OUTPUT panel, it may bring you the correct display effect.

    Cant print letters such as å, ä, ö in PowerShell and when I do it prints, for example, ä

    Please do not use Code Runner if there is no special requirement. Python works better as an official extension.

  • Configure the following launch.json, use Run Without Debugging, and the result is output in the DEBUG CONSOLE panel

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Current File",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "internalConsole",
                "justMyCode": true
            }
        ]
    }
    

    Cant print letters such as å, ä, ö in PowerShell and when I do it prints, for example, ä

huangapple
  • 本文由 发表于 2023年5月15日 03:25:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76249315.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定