Bottom Page

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.
Quote
#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:
Quote
#3
Right, thanks, how do I define the file on which the replacements will run?
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Error Message Coming Up When Running Code eddywinch82 0 246 Feb-10-2020, 11:48 PM
Last Post: eddywinch82
  Running tests in a sibling directory to code sodhiar 1 225 Nov-07-2019, 11:28 PM
Last Post: MckJohan
  NameError: name 'display' is not defined when running code on power bi beginner1 2 2,852 Jul-24-2019, 11:03 AM
Last Post: beginner1
  Syntax Error when running code codeman 3 688 Apr-02-2019, 11:47 AM
Last Post: codeman
  inkscape plugin write in python error costycnc 5 823 Jan-25-2019, 08:02 PM
Last Post: costycnc
  code keeps running if i use from threading import timer? birddseedd 3 467 Jan-25-2019, 05:00 AM
Last Post: stullis
  Data manipulation code running but not functioning correctly homotextual 1 367 Dec-30-2018, 03:19 PM
Last Post: ichabod801
  Running remote code? MuntyScruntfundle 1 484 Nov-25-2018, 05:05 PM
Last Post: Larz60+
  Running another python file from code Stefanovietch 1 564 Nov-18-2018, 09:59 PM
Last Post: ichabod801
  Exporting Python Output to Notepad Nirmal 4 854 Sep-02-2018, 02:36 PM
Last Post: Nirmal

Forum Jump:


Users browsing this thread: 1 Guest(s)