Something like:
import fileinput for lines in fileinput.FileInput("test.txt", inplace=1): lines = lines.strip() if lines == '': continue print lines
But nothing is being printed on stdout.
Assuming some string named foo:
foo
foo.lstrip() # to remove leading white space foo.rstrip() # to remove trailing whitespace foo.strip() # to remove both lead and trailing whitespace
fileinput seems to be for multiple input streams. This is what I would do:
fileinput
with open("test.txt") as file: for line in file: line = line.rstrip() if line: print(line)
1.4m articles
1.4m replys
5 comments
56.9k users