Python runs differently in NPP Exec Console vs Windows Console.
-
prefix = ' ' body = '┌──────────────────────────────────────────────────────────────┐' suffix = ' ' print(prefix+body+suffix)
Produces this error ONLY IN NPP EXEC CONSOLE (not in Windows console).
NPP_SAVE: D:\EveMarketMaster\Junk.py C:\Users\mltco\AppData\Local\Programs\Python\Python38\python.exe "D:\EveMarketMaster\Junk.py" Process started (PID=11160) >>> Traceback (most recent call last): File "D:\EveMarketMaster\Junk.py", line 8, in <module> print(prefix+body) File "C:\Users\mltco\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 95-158: character maps to <undefined> <<< Process finished (PID=11160). (Exit code 1)
I have a workaround, but I’d need to be able to detect from within the Python code whether I was running under the WINDOWS console or the NPP EXEC console and I can’t find any way to do that.
Is there a fix for this?
-
@Mark-Tinney-0 said in Python runs differently in NPP Exec Console vs Windows Console.:
prefix = ’ ’
body = ‘┌──────────────────────────────────────────────────────────────┐’
suffix = ’ ’print(prefix+body+suffix)
Is this something you have under your control?
If so, you could create a unique environment variable and check this from your script.
Something like this.In NppExec execute you do
NPP_SAVE $(FULL_CURRENT_PATH) set_env CALLED_FROM_NPP_EXEC=1 D:\ProgramData\Python\Python_embed_382_64\python.exe "$(FULL_CURRENT_PATH)" env_unset CALLED_FROM_NPP_EXEC
and in python script you do
import os print(f'{"CALLED_FROM_NPP_EXEC" in os.environ = }')