[Python-checkins] r78972 - python/trunk/Lib/py_compile.py

benjamin.peterson python-checkins at python.org
Mon Mar 15 04:02:37 CET 2010


Author: benjamin.peterson
Date: Mon Mar 15 04:02:37 2010
New Revision: 78972
Log:
clean up files correctly
Modified:
 python/trunk/Lib/py_compile.py
Modified: python/trunk/Lib/py_compile.py
==============================================================================
--- python/trunk/Lib/py_compile.py	(original)
+++ python/trunk/Lib/py_compile.py	Mon Mar 15 04:02:37 2010
@@ -103,13 +103,12 @@
 directories).
 
 """
- f = open(file, 'U')
- try:
- timestamp = long(os.fstat(f.fileno()).st_mtime)
- except AttributeError:
- timestamp = long(os.stat(file).st_mtime)
- codestring = f.read()
- f.close()
+ with open(file, 'U') as f:
+ try:
+ timestamp = long(os.fstat(f.fileno()).st_mtime)
+ except AttributeError:
+ timestamp = long(os.stat(file).st_mtime)
+ codestring = f.read()
 if codestring and codestring[-1] != '\n':
 codestring = codestring + '\n'
 try:
@@ -123,14 +122,13 @@
 return
 if cfile is None:
 cfile = file + (__debug__ and 'c' or 'o')
- fc = open(cfile, 'wb')
- fc.write('0円0円0円0円')
- wr_long(fc, timestamp)
- marshal.dump(codeobject, fc)
- fc.flush()
- fc.seek(0, 0)
- fc.write(MAGIC)
- fc.close()
+ with open(cfile, 'wb') as fc:
+ fc.write('0円0円0円0円')
+ wr_long(fc, timestamp)
+ marshal.dump(codeobject, fc)
+ fc.flush()
+ fc.seek(0, 0)
+ fc.write(MAGIC)
 
 def main(args=None):
 """Compile several source files.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /