Skip to content

Instantly share code, notes, and snippets.

Last active Nov 9, 2016
What would you like to do?
Strip trailing whitespace from file
#!/usr/bin/env python2
strip trailing whitespace from file
usage: <file>
code is placed into public domain
import sys
if len(sys.argv[1:]) != 1:
content = ''
outsize = 0
inp = outp = sys.argv[1]
with open(inp, 'rb') as infile:
content =
with open(outp, 'wb') as output:
for line in content.splitlines():
newline = line.rstrip(" \t")
outsize += len(newline) + 1
output.write(newline + '\n')
print("Done. Stripped %s bytes." % (len(content)-outsize))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment