Displaying Swedish characters correctly on a Windows command line using Python in Notepad ++

The title explains well. I installed Notepad ++ to open a Python script on the command line when I click F8, but all Swedish characters look confused when opened in CMD, but are great for example in IDLE.

This simple code example:

#!/usr/bin/env python
#-*- coding: UTF-8 -*-
print "åäö"

It looks like this .

As you can see, the output of the batch file that I use to open Python in cmd below shows the characters correctly, but not the Python script above it. How to fix it? I just want to show the characters correctly, I did not necessarily use UTF-8.

I open the file in cmd using this method .

Update: Allowed. Added the line "chcp 1252" at the top of the batch file, and then the cls line below it to remove the message about what character encoding it uses. Then I used "# - encoding: cp1252 -" in a python script and changed the font in cmd to Lucida Console. This can be done by clicking the cmd icon in the upper right corner of the cmd window and go to properties.

+3
source share
4 answers

Python Unicode Windows. , Unicode Unicode (, u'string ') , coding:.

, ( UTF-8 x.py ):

# coding: utf8
print u"åäö"

:

C:\>chcp
Active code page: 437

C:\>x
åäö

, .

0

UTF-8, UTF-8. Unicode UTF-16, UTF-8.

print u"åäö"
+4

, cp1252

C: > chcp 1252

1252, , .

0
source

Set the encoding: # -*- coding: ISO-8859-1 -*-

This worked for me, and I tried many different solutions to get it working with the Visual Studio IDE for Python.

# -*- coding: ISO-8859-1 -*-
print ("åäö")
0
source

Source: https://habr.com/ru/post/1741614/


All Articles