Index: spongenet/trunk/spongenet/expand.py =================================================================== --- spongenet/trunk/spongenet/expand.py (revision 344) +++ spongenet/trunk/spongenet/expand.py (revision 345) @@ -268,10 +268,8 @@ >>> ref_path = xml_subdir + os.extsep + "ref" >>> xml_path = xml_subdir + os.extsep + "xml" - >>> ref_handle = open(ref_path) - >>> xml_handle = open(xml_path) - >>> reffile = ref_handle.read() - >>> xmlfile = xml_handle.read() - >>> ref_handle.close() - >>> xml_handle.close() + >>> with open(ref_path) as ref_handle: + ... reffile = ref_handle.readlines() + >>> with open(xml_path) as xml_handle: + ... xmlfile = xml_handle.readlines() >>> reffile == xmlfile True @@ -293,10 +291,9 @@ # Write a combined xml sponge data file. path = xml_subdir + os.extsep + "xml" - handle = open(path, "w") - handle.write(header) - handle.write("\r\n") - handle.writelines(lines) - handle.write("\r\n") - handle.close() + with open(path, "w") as handle: + handle.write(header) + handle.write("\r\n") + handle.writelines(lines) + handle.write("\r\n") # Remove the xml sponge data file subdirectory. @@ -331,10 +328,8 @@ >>> truths = [] >>> for ref_path,xml_path in paths: - ... ref_handle = open(ref_path) - ... xml_handle = open(xml_path) - ... reffile = ref_handle.read() - ... xmlfile = xml_handle.read() - ... ref_handle.close() - ... xml_handle.close() + ... with open(ref_path) as ref_handle: + ... reffile = ref_handle.readlines() + ... with open(xml_path) as xml_handle: + ... xmlfile = xml_handle.readlines() ... truths.extend((reffile == xmlfile, ... os.path.exists(os.path.splitext(xml_path)[0]),))