Community
    • Login

    Python runs differently in NPP Exec Console vs Windows Console.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    console problem
    2 Posts 2 Posters 334 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Mark Tinney 0M Offline
      Mark Tinney 0
      last edited by

      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?

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE Offline
        Ekopalypse @Mark Tinney 0
        last edited by Ekopalypse

        @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 = }')
        
        1 Reply Last reply Reply Quote 1

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors