Python Forum

Full Version: Search & Replace - Newlines Added After Replace
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

the below script works, but it adds a new line after it replaces

I cant understand why
it should just do a straight replace


with open('c:/Users/Dan/Desktop/Replace.txt') as f:            
    for l in f:
        #s = l.split()
        s = l.split('|')
        editor.replace(s[0], s[1])
Replace file
apple|pear
hello|Hi
what is editor?
don't forget that each line in the file ends with '\n' (i.e. new line). If you print the line print will also add new line. you can use optional end parameter OR strip the whitespace:
>>> line='somethin, something else\n'
>>> print(line)
somethin, something else

>>> print(line, end='')
somethin, something else
>>> print(line.strip())
somethin, something else
>>>
Hello Buran,

This is to do search and replacement in Notepad++ editor
I am doing lots of search and replace

originally
s = l.split()
does not cause this issue
i tried the below
 editor.replace(s[0], s[1])
 editor.line.strip()
if it is Python Script for Notepad++ plug-in related and there was no problem before, you may want to raise an issue on their Github https://github.com/bruderstein/PythonScript/issues