mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +00:00
Clean up syntax for some scripts.
This commit is contained in:
parent
aba74bddd6
commit
e4a3380bb0
7 changed files with 115 additions and 87 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue