In a text file I’m trying to replace, I’m trying to delete an extra line break ie. convert
test="
123"
to
test="123"
What I currently have is:
f = open("file.txt")
o = open("newfile.txt","w")
while 1:
line = f.readline()
if not line: break
line = line.replace('test="\r','test="')
o.write(line)
o.close()
The problem is that it returns
test="123"
with an invisible character between the <“> and the <123>. Is there some better alternative to what I’m currently doing? I’m not very proficient with python; thanks!
Your code have some flaws:
\r, ignoring the\non windows – this is your “invisible” character I think (windows uses\r\nas a linebreak in textfiles, linux\nand Mac\r)here is another version (might be close to that what you want;) ):