æøå ÆØÅ 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.
-
@PeterJones So what are you telling me? My solution is a bad way? Should i do it any other way? What problems might i meet down the line if i do my solution?
Because as i said I’m looking for a simple one click solution.Not an advanced “fixing .txt files” or “remember to add a text line to every time i use æøå” or “having to reprogram your python” solutions. Since i reinstall npp, python and even also my OS alot.
-
@Kay-Haldor-Øvredal-Gjuvsland said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
@PeterJones So what are you telling me? My solution is a bad way? Should i do it any other way? What problems might i meet down the line if i do my solution?
Because as i said I’m looking for a simple one click solution.Not an advanced “fixing .txt files” or “remember to add a text line to every time i use æøå” or “having to reprogram your python” solutions. Since i reinstall npp, python and even also my OS alot.
Your solution is limited. By picking the ANSI encoding, then you can only print the <256 in whichever character set is default on your installation/configuration of Windows. So if you send instructions to someone whose default character set happens to be different, your code will output different characters on their system, which may be confusing to them (and they may ask you for help, and would would need to be able to explain why it’s different); further, there are a plethora of Unicode characters that exist that are not in whatever ANSI codepage you are using, and you cannot print any of those in your current setup. If you are fine with the limitations (you won’t be sharing the code, and/or you will never want to print any character that isn’t in your default codepage), then feel free to use that one. But UTF-8 was designed to give anyone access to the entirety of Unicode, rather than a less-than-256 character subset of characters, and if you have the choice, you should be moving away from the 1980’s-style dependence on codepage, because by the 90’s, everyone knew that had been the wrong direction, and by the 2000’s, Unicode was a popular enough workaround that everyone should have migrated away from codepages then.
Since one of the stated goals of your post was to provide information that was googleable, I wanted to make sure that future readers would understand that they don’t have to limit themselves to <256 character when using python in Notepad++ & NppExec.
-
Interesting!
For me I’ll only be using python for simple to middle difficulty math problems.
Mainly because my school is making me.
They want me to install Spyder but i think its such a heavy program and takes for ever to start up, and it always ask for updates that takes up to 15 minutes to install. So i just wanted to make NPP work for my use.
Its a fast and simple solution for the time being.But i will definitely keep this in mind! Specially if i need more characters in my Unicode table :)
I wonder though, Why ain’t Python set to this table as default? I mean if it has so many more characters making it a wider solution for everyone and all that.
-
@Kay-Haldor-Øvredal-Gjuvsland said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
Why ain’t Python set to this table as default?
It is, under normal circumstances (like a normal command line). But as I said earlier, in the NppExec environment, the STDOUT from Python is captured, and once it’s captured, Python cannot tell what encoding that STDOUT wants; thus, you have to tell it (either using the command-line option or the environment variable) that you really do want UTF-8.
-
Yeah ok…
Makes no sense though but ok :P
i tested your python -X utf8 -c “print(‘æøå\u263a’)” where it now shows error message:
python -X utf8 -c "print('æøå\u263a')" ^^^^
SyntaxError: invalid syntax
Just showing how big off a headache this is. So ill just end my curiosity here and be happy that i found an easy solution to my problem, hoping that others will find as pleasing as i did.
I thank you though, my good sir, for making sure that “the more advanced users” learn that there is more to it than my simple solution! :) And to trying to teach me as well! <3
-
i tested your python -X utf8 -c “print(‘æøå\u263a’)” where it now shows error message:
python -X utf8 -c "print('æøå\u263a')" ^^^^
SyntaxError: invalid syntax
You ran python, and then pasted in the command. That is not what my screenshots showed. You should type that inside the NppExec console directly. And it will only work if
python -V
shows v3.12 or similar; if it shows 2.7.xx, then the-X utf8
will not work for you.Just showing how big off a headache this is.
All you have to do is literally do what I showed in the screenshot, and it will work. You have yet to try what I showed, so you are causing your own headache…
Good luck.
-
LOL You can write in the NPPExec Console window?? I didnt even know that! But how in the world would that help me if i made a script with ÆØÅ in it?
Lets say i write this code:
from math import sqrt print("Vi skal løse andregradslikningen ax^2+bx+c=0") a = float(input("a = ")) if a == 0: print("Med a = 0 blir det ikke en annengradslikning.") else: b = float(input("b = ")) c = float(input("c = ")) d = b**2 - 4*a*c if d < 0: print("Ingen løsning.") elif d == 0: x1 = -b/(2*a) print("En løsning x =", round(x1, 2)) else: x1 = (-b+sqrt(d))/(2*a) x2 = (-b-sqrt(d))/(2*a) print("To løsninger x =", round(x1,2), "og x =", round(x2, 2))
Am i supposed to copy paste this directly into the NppExec console every time i want to run it? Btw i tested that and got a couple off error messages :P
And also not once did you mention anywhere that i was supposed to add this directly into the console window :P So i kindly disagree I’m not causing my own headaches ;)
-
LOL You can write in the NPPExec Console window?? I didnt even know that!
Typing into the console is 100% equivalent to running an NppExec script with the same content.
But how in the world would that help me if i made a script with ÆØÅ ??
Sorry. I assumed you knew enough about python to be able to translate my python one-liner
-c
syntax into the equivalent calling of a script. (In general, this is the wrong place to answer such programming-specific concepts. As long as it was in how to make Python do what you want in the uniqueness of the NppExec environment, it’s on topic for the forum, but generic python questions are off topic here.)If your normal NppExec script runs
python $(FILE_NAME)
in order to execute your python code, then you would change it topython -X utf8 $(FILE_NAME)
Am i supposed to copy paste this directly into the NppExec console every time i want to run it?
Of course not. If you seriously think that was my implication, then you need to go find someplace to learn more about using python from the command line.
And also not once did you mention anywhere that i was supposed to add this directly into the console window :P So i kindly disagree I’m not causing my own headaches ;)
As I pasted an image showing I had done exactly that, and as that the results would have been identical if you had pasted the command I gave you into the NppExec run-a-command-or-script dialog box (which would have been the next most logical conclusion of what my screenshot was showing you to do), I thought my instructions were sufficient for someone who understood and used python. I am sorry that it was not enough for you
-
@PeterJones said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
Of course not. If you seriously think that was my implication, then you need to go find someplace to learn more about using python from the command line.
Sorry bro but that ain’t happening :P i absolutely hate coding and do not plan to widen my knowledge on the matter. All i wanted was an quick and easy way to fix a very very small but irritating issue.
@PeterJones said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
Sorry. I assumed you knew enough about python to be able to translate my python one-liner -c syntax into the equivalent calling of a script.
As stated in an earlier reply i am an absolute “noobster” on the matter.
@PeterJones said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
If your normal NppExec script runs python $(FILE_NAME) in order to execute your python code, then you would change it to python -X utf8 $(FILE_NAME)
Thanks for this. Absolutely gold. I did this and it works now! Ty ty my good sir.
@PeterJones said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
(which would have been the next most logical conclusion of what my screenshot was showing you to do)
As i said, I’m a noob so naturally this is not an logical conclusion for me.
@PeterJones said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
I am sorry that it was not enough for you
Working in the field off support for the past 20 years i can assure you that assuming the customer/user have knowledge about anything is wrong. Always assume they know nothing and write your solutions as such. On a forum such as this its even more important considering a lot more eyes will find this solution for them self.
So just to sum it up. In order to get ÆØÅ working in NppExec console go into NPP and go to “Plugins” and hover the mouse over “NppExec” and press “Console Output…{OEM/OEM}”. Change both sides (Input and Output) to ASCI (Windows).
OR (an even better solution posted by @PeterJones, but with an extra step)
When you press F6 where it should say something like (If you copy pasted this from a different forum like i did):
npp_save
cd “$(CURRENT_DIRECTORY)”
python “$(FILE_NAME)”Change this to
npp_save
cd “$(CURRENT_DIRECTORY)”
python -X utf8 “$(FILE_NAME)”Then go to “Plugins” and hover the mouse over “NppExec” and press “Console Output…{OEM/OEM}”. Change both sides (Input and Output) to UTF-8.
This is a better solution because, as @PeterJones mention earlier, it has a wider charset then ASCI does. Wider charset = even more special symbols.
-
@CyReX1986 said:
You can write in the NPPExec Console window?? I didnt even know that!
I don’t use NppExec very much, but when I have used it it has been to type stuff into its console window. I’ve just kind of always known this was possible. But I tried to put myself in total noob shoes to see how hard it is to find out that you can do this.
The link provided earlier in this thread opens the online help for NppExec. Poking around in there, I see Basic Usage as a section header, and under that Do something (intro). Literally the first way to do something says “using NppExec’s Console allows you to enter some command and execute it by pressing Enter”.
There used to be a common sense thing that when you’re starting to use something new, you do at least a glance-through of its manual. I’m probably old school, though.
It also pays to be a bit humble when others are trying to help; makes the whole process smoother.
-
@Alan-Kilborn said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
You can write in the NPPExec Console window?? I didn’t even know that!
Yeah this was me having an “omg, that’s cool” / “I am an idiot” moment ^^ It might have been lost in translation though and can easily be misinterpreted as something else. If so i am sorry.
@Alan-Kilborn said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
Do something (intro). Literally the first way to do something says “using NppExec’s Console allows you to enter some command and execute it by pressing Enter”.
English is not my first language so that pretty much went straight over my head. I interpreted this as “making a .txt or .py file (or any file used for the console)” and writing the command line there and sending it to the console. Not as pressing the mouse inside the console and using it as a “command prompt/terminal” since that is not what i set out to do in the first place.
@Alan-Kilborn said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
There used to be a common sense thing that when you’re starting to use something new, you do at least a glance-through of its manual. I’m probably old school, though.
If one is doing something they want to learn and set out to do so then ofc read the manual! But for my use, nah i see that as an waste of time in my matter. Yet i did go into the link and glance over it. Remember i made this post to help my future self and hopefully others, not be schooled in how to use npp/python. All though i do appreciate all the help that has been given! And i am sure others will too!
@Alan-Kilborn said in æøå ÆØÅ Python in Notepad++ with NppExec Norwegian, Icelandic, Danish and the Faroe Islands:
It also pays to be a bit humble when others are trying to help; makes the whole process smoother.
I believe I’ve been more then “a bit” humble in this thread. But yeah you are right, this thread did not go very smoothly.