Python Forum
Running python code meant for Notepad++ plugin independently
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running python code meant for Notepad++ plugin independently
#1
Please excuse my ignorance, but I am trying to run this code: https://python-forum.io/Thread-Matching-...ace-script

with open('C:/fix.txt') as f:
    for l in f:
        s = l.split()
        editor.replace(s[0], s[1])
independently from Notepad++ (as it hangs on large texts). I have Python 3.5 installed on Windows. How would I have to edit that code to define the file on which the replacements must be made? Currently, only the file with the replacement set is defined.
Reply
#2
I'm not sure if this helps, but that won't work on Windows. First, you need to use the forward slash "\" not the backslash "/". Second, you need to escape the forward slash like this: "\\". So the code should look like this: with open('C:\\fix.txt') as f:
Reply
#3
Right, thanks, how do I define the file on which the replacements will run?
Reply
#4
(Jan-28-2019, 05:39 PM)greektranslator Wrote: Right, thanks, how do I define the file on which the replacements will run?

To my knowledge, a txt file open in this way runs within the python environment, thus not opening any external editors. I'm still a newbie myself. But I've been working on a project that deals with txt editing. It's been my experience that no external editors (notepad, notepad++, gedit, vim, etc.) opens when you run with open() as f:. Beyond that, what you're doing with the for loop, is beyond my knowledge. If I were you, I'd make a smaller test txt file and run some experiments before running it on the real thing.

Scratch that, I reread your post.

To define the file that you are editing, that is the part in the quotes. So think about it this way: with open("C:\\absolute\\path\\to\\file.txt") as f
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code not running even without errors Azdaghost 2 141 8 hours ago
Last Post: Azdaghost
  python code not running Azdaghost 1 180 Apr-22-2025, 08:44 PM
Last Post: deanhystad
  Setup Notepad++ for python LavaCreeperKing 8 15,140 Mar-06-2025, 12:30 PM
Last Post: DeaD_EyE
  writing and running code in vscode without saving it akbarza 5 2,410 Mar-03-2025, 08:14 PM
Last Post: Gribouillis
  Python: How to import data from txt, instead of running the data from the code? Melcu54 1 650 Dec-13-2024, 06:50 AM
Last Post: Gribouillis
Exclamation Error in the asyncio plugin Maden4ik 3 2,003 Aug-01-2024, 04:33 PM
Last Post: bowlofred
Bug Error in the asyncio plugin Maden4ik 2 1,019 Jul-31-2024, 03:31 PM
Last Post: deanhystad
  problem in running a code akbarza 7 2,358 Feb-14-2024, 02:57 PM
Last Post: snippsat
  the order of running code in a decorator function akbarza 2 1,356 Nov-10-2023, 08:09 AM
Last Post: akbarza
  how include a python code in notpad++ plugin akbarza 2 1,562 Sep-25-2023, 08:25 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020