Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Running python code meant for Notepad++ plugin independently greektranslator Programmer named Tim Posts: 6 Threads: 3 Joined: Jul 2017 Reputation: 0 Likes received: 0 #1 Jan-28-2019, 04:29 PM (This post was last modified: Jan-28-2019, 04:30 PM by greektranslator. Edited 1 time in total.) 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. maxtimbo Programmer named Tim Posts: 11 Threads: 4 Joined: Jan 2019 Reputation: 0 Likes received: 0 #2 Jan-28-2019, 05:22 PM 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: greektranslator Programmer named Tim Posts: 6 Threads: 3 Joined: Jul 2017 Reputation: 0 Likes received: 0 #3 Jan-28-2019, 05:39 PM Right, thanks, how do I define the file on which the replacements will run? maxtimbo Programmer named Tim Posts: 11 Threads: 4 Joined: Jan 2019 Reputation: 0 Likes received: 0 #4 Jan-28-2019, 06:03 PM (This post was last modified: Jan-28-2019, 06:03 PM by maxtimbo. Edited 2 times in total. Edit Reason: missed quotes ) (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 « Next Oldest | Next Newest »

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)