Clean up syntax for some scripts.

This commit is contained in:
Florent Xicluna 2010-08-09 12:24:20 +00:00
parent aba74bddd6
commit e4a3380bb0
7 changed files with 115 additions and 87 deletions

View file

@ -6,6 +6,7 @@ import os
import sys
import getopt
def main():
tabsize = 8
try:
@ -23,11 +24,11 @@ def main():
for filename in args:
process(filename, tabsize)
def process(filename, tabsize):
try:
f = open(filename)
text = f.read()
f.close()
with open(filename) as f:
text = f.read()
except IOError as msg:
print("%r: I/O error: %s" % (filename, msg))
return
@ -43,10 +44,10 @@ def process(filename, tabsize):
os.rename(filename, backup)
except os.error:
pass
f = open(filename, "w")
f.write(newtext)
f.close()
with open(filename, "w") as f:
f.write(newtext)
print(filename)
if __name__ == '__main__':
main()