3 def strip_file(filename
, write
, report
):
4 lines
= enumerate(open(filename
).readlines())
6 f
= open(filename
, "w")
7 for index
, line
in lines
:
8 if report
and line
.endswith(" \n"):
9 print "%s, line %s" % (filename
, index
+ 1)
11 f
.write(line
.rstrip() + "\n")
14 from optparse
import OptionParser
15 p
= OptionParser("usage: %prog [options] filename")
16 p
.add_option("-d", "--dry", action
="store_true", dest
="dry",
17 help="Do not modify files.")
18 p
.add_option("-v", "--verbose", action
="store_true", dest
="verbose",
19 help="Report all changes.")
20 options
, args
= p
.parse_args()
22 options
.verbose
= True
24 strip_file(args
[0], not options
.dry
, options
.verbose
)
28 if __name__
== "__main__":