I have a file that contains a value of 2000.00.
But it contains spaces after 2000.00 and blank lines.
I want to remove all spaces and empty lines, if someone can give some idea, I tried several ways, but did not succeed.
One of the ways I'm tired is below
# Read lines as a list fh = open("transfer-out/" + file, "r") lines = fh.readlines() fh.close() # Weed out blank lines with filter lines = filter(lambda x: not x.isspace(), lines) # Write "transfer-out/"+file+".txt", "w" fh = open("transfer-out/"+file, "w") #fh.write("".join(lines)) # should also work instead of joining the list: fh.writelines(lines) fh.close()
source share