Python Forum
Running python code meant for Notepad++ plugin independently - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Running python code meant for Notepad++ plugin independently (/thread-15710.html)



Running python code meant for Notepad++ plugin independently - greektranslator - Jan-28-2019

Please excuse my ignorance, but I am trying to run this code: https://python-forum.io/Thread-Matching-whole-words-in-find-replace-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.


RE: Running python code meant for Notepad++ plugin independently - maxtimbo - Jan-28-2019

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:


RE: Running python code meant for Notepad++ plugin independently - greektranslator - Jan-28-2019

Right, thanks, how do I define the file on which the replacements will run?


RE: Running python code meant for Notepad++ plugin independently - maxtimbo - Jan-28-2019

(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