æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands
-
So i’ve scoured the internett trying to figure out how to get æøå to work with python in Notepad++ without any luck. There is several answers out there but they re just way to advanced for me to understand. So i’ve been playing around in NPP for a while now and i finally figured it out!
Im writing this post just so i can my self find the answer later down the line and hopefully help others with the same problem.
The solution was ridiculously easy.
The following is a working solution as off writing this post with Notepad++ version 8.7.1 (64-bit) installed on Windows 10 with Python version 3.12
In NPP go to “Plugins” and hover the mouse over “NppExec” and press “Console Output…{OEM/OEM}”. Change both sides (Input and Output) to ASCI (Windows). And there you go! It should work now :)
Just in case ill add that i’ve set Encoding to UTF-8
Ill add sone diffrent words so the search engine will find this post easier.
æøå ÆØÅ æ ø å Æ Ø Å Norsk Dansk Islandsk Færøysk Norwegian Icelandish Faroese Norge Danmark Island the Færøyene Norway Iceland Denmark the Faroe Islands
Getting NPP with Python through NppExec to print æ ø å Æ Ø Å
-
The “Python and UTF-8” section here seems to be related:
https://d0vgan.github.io/nppexec/?q=4.6.4 -
@Kay-Haldor-Øvredal-Gjuvsland ,
Another option is to set that Console Output… dialog to UTF-8 for both input and output,
… and to use python3’s
-X utf8
command-line argument.By adding a
\u236a
-encoded smiley, you can see better that without that-X
, python is applying heuristics to determine what encoding to use when printing; and the NppExec environment is capturing the STDOUT/STDERR from anything executed in its Console, so the heuristics don’t necessarily come to the right conclusion.Here are some screenshots in OEM/OEM, ANSI/ANSI, and UTF8/UTF8:
python -c "print('æøå')" python -c "print('æøå\u263a')" python -X utf8 -c "print('æøå\u263a')"
OEM ANSI UTF-8 The error message for the
python -c "print('æøå\u263a')"
shows that Python3 is trying to use thecharmap
codec, which is what it uses when it’s using one of the ANSI-style codepage/character-map-encodings rather than a full unicode encoding like UTF-8.Thus, without forcing python3 to correctly use UTF-8 output in the NppExec environment, you have to tell NppExec that it needs to interpret the output from python as your ANSI codepage.
… Looking at @Vitalii-Dovgan’s link, an alternative to using the
-X utf8
and choosing UTF8/UTF8 in the plugin menu, is to set the environment variable and thenpe_console
as shown (the npe_console given is equivalent to setting UTF-8/UTF-8 in the plugin menu, but just for the active script). -
@PeterJones Very nice! I’ve been looking for a post like this for the last 6 months without luck. all though its only like 2-3 hours like 5 times over the last 6 months :P I wish these posts would’ve shown up when i tried searching >.< But as i said i do not want to have to write any code every time i wish to use æøå since we use these letters a lot in my country. So I’m happy i finally found the solution to just set it and would just always work :)
Btw i tested setting it to UTF-8 in the menu you posted and it did not work. It gave me ��� ��� instead of the µ°Õ ãÏ┼ that OEM (DOS) gives :P But ANSI (Windows) works perfectly :)
I also posted this post on Stackoverflow’s forum but it got instantly moved to “Off topic” :P But as long as it shows up in google then I’m happy!
-
@Vitalii-Dovgan Thank you very much for the link!
Looking at the document makes me realize that I’ve tried a lot of these and never got it to work. Also it is just way too advanced for little old noobster me :P
I was just looking for an simple press of a button in order to fix this indefinitely without issue. And I am pretty happy that I’ve finally found the solution xD
And will you look at that! Searching google for “notepad++ how to get æøå in npp_exec python” and this post comes up as the very first search :D
-
@Kay-Haldor-Øvredal-Gjuvsland said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
Btw i tested setting it to UTF-8 in the menu you posted and it did not work. It gave me ��� ��� instead of the µ°Õ ãÏ┼ that OEM (DOS) gives :P But ANSI (Windows) works perfectly :)
As I said, if you have NppExec set to UTF-8, you must also ensure that python is outputting UTF-8 when it’s running. Just setting the UTF-8 option in NppExec is not sufficient if python is not configured to output UTF-8. You can do this with either the
-X utf8
command line option passed to the python.exe, or by setting the environment variable that’s in the document @Vitalii-Dovgan linked to.I literally showed you a screenshot where it showed the � vs the right output, and what the command looked like that did each, so I am quite confident it works.