doc/mkdocdeps.py: Use "with" statement for the output file
authorW. Trevor King <wking@tremily.us>
Sat, 5 Apr 2014 17:31:06 +0000 (10:31 -0700)
committerDavid Bremner <david@tethera.net>
Mon, 21 Apr 2014 12:31:45 +0000 (21:31 +0900)
Before this patch, the open was unnecessarily early and relied on the
process cleanup to close.  Neither one of these was a real problem,
but PEP 343's context managers (which landed in Python 2.5) make
proper cleanup very easy.

[1]: http://legacy.python.org/dev/peps/pep-0343/

doc/mkdocdeps.py

index de1cbb8f2bedc59c5f5fc46280a7282f22e9503a..b87fe3e80c0fdc395a1efc4d8e6e892c829bf095 100644 (file)
@@ -9,10 +9,10 @@ import conf
 
 roff_files = []
 rst_files = []
-out=open(outfile,'w')
 for page in conf.man_pages:
     rst_files = rst_files + ["{0:s}/{1:s}.rst".format(srcdir,page[0])]
     roff_files = roff_files + ["{0:s}/man/{1:s}.{2:d}".format(builddir,page[0],page[4])]
 
-out.write ('MAN_ROFF_FILES := ' + ' \\\n\t'.join(roff_files)+'\n')
-out.write ('MAN_RST_FILES := ' + ' \\\n\t'.join(rst_files)+'\n')
+with open(outfile, 'w') as out:
+    out.write('MAN_ROFF_FILES := ' + ' \\\n\t'.join(roff_files) + '\n')
+    out.write('MAN_RST_FILES := ' + ' \\\n\t'.join(rst_files) + '\n')