3 # This script removes trailing whitespace from files.
4 # It doesn't remove trailing newlines.
5 # As a side-effect, it converts line endings to Unix-style (LF).
9 # Iterate through all arguments. When the script is called
10 # with a wildcard (for example 'remove-trailing-whitespace.py *'),
11 # it's the *shell* that will expand the wildcard, and pass all
12 # resulting paths as arguments to the script.
14 for pathname in sys.argv[1:]:
15 if os.path.isfile(pathname):
16 fd = open(pathname,mode='U') # open in universal newline mode
18 for line in fd.readlines():
19 lines.append( line.rstrip() )
22 fd = open(pathname,mode='w')