Start New Discussion within our Software Development Community
Hey everyone, new here.  I'm looking for a little help with my
program. Its supposed to take a txt file called test.txt, and
removes all spaces trailing at the end of lines.  ex. (note the
spaces) "python " -> "python" "daniweb is great" -> "daniweb is
great" " forum" -> " forum"  The code below has gone through
many rewrites, but it still doesn't work. At first it would
delete a good chunk of the txt in the file seemingly randomly,
but now it deletes all the text from the file.  txt =
open(test.txt,"r") loriginal = f.readline() txt =
open(test.txt,"w") l = line.split() for i in range(len(l)):
if l[i] == "/n":         del line[i:]  Needless to say, this
piece of code doesn't work. Can anyone shed some light on this
and help me out?  Thanks in advance.   You can use a regular
expression  import re sp_regex = re.compile(r"[ \t]+$",
re.MULTILINE) filename = "test.txt" with open(filename) as f_in:
content = with open(filename, "w") as f_out: