Created
October 5, 2011 06:15
-
-
Save codebrainz/1263776 to your computer and use it in GitHub Desktop.
Cleanup trailing spaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import sys | |
| filenames = sys.argv[1:] | |
| def backup_file (fn): | |
| open ("%s~" % fn, "w").write (open (fn, "r").read ()) | |
| for fn in filenames: | |
| #backup_file (fn) | |
| contents = open (fn, "r").read () | |
| lines = contents.split ('\n') | |
| with open (fn, "w") as fobj: | |
| for line in lines: | |
| line = line.rstrip () | |
| fobj.write ("%s\n" % line) | |
| contents = open (fn, "r").read () | |
| contents.rstrip () | |
| while contents[-1] in " \t\r\n": | |
| contents = contents[:-1] | |
| open (fn, "w").write ("%s\n" % contents) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment