Changeset 345
- Timestamp:
- 08/30/10 14:24:24
- Files:
-
- spongenet/trunk/spongenet/expand.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spongenet/trunk/spongenet/expand.py
r344 r345 268 268 >>> ref_path = xml_subdir + os.extsep + "ref" 269 269 >>> xml_path = xml_subdir + os.extsep + "xml" 270 >>> ref_handle = open(ref_path) 271 >>> xml_handle = open(xml_path) 272 >>> reffile = ref_handle.read() 273 >>> xmlfile = xml_handle.read() 274 >>> ref_handle.close() 275 >>> xml_handle.close() 270 >>> with open(ref_path) as ref_handle: 271 ... reffile = ref_handle.readlines() 272 >>> with open(xml_path) as xml_handle: 273 ... xmlfile = xml_handle.readlines() 276 274 >>> reffile == xmlfile 277 275 True … … 293 291 # Write a combined xml sponge data file. 294 292 path = xml_subdir + os.extsep + "xml" 295 handle = open(path, "w") 296 handle.write(header) 297 handle.write("<root>\r\n") 298 handle.writelines(lines) 299 handle.write("\r\n</root>") 300 handle.close() 293 with open(path, "w") as handle: 294 handle.write(header) 295 handle.write("<root>\r\n") 296 handle.writelines(lines) 297 handle.write("\r\n</root>") 301 298 302 299 # Remove the xml sponge data file subdirectory. … … 331 328 >>> truths = [] 332 329 >>> for ref_path,xml_path in paths: 333 ... ref_handle = open(ref_path) 334 ... xml_handle = open(xml_path) 335 ... reffile = ref_handle.read() 336 ... xmlfile = xml_handle.read() 337 ... ref_handle.close() 338 ... xml_handle.close() 330 ... with open(ref_path) as ref_handle: 331 ... reffile = ref_handle.readlines() 332 ... with open(xml_path) as xml_handle: 333 ... xmlfile = xml_handle.readlines() 339 334 ... truths.extend((reffile == xmlfile, 340 335 ... os.path.exists(os.path.splitext(xml_path)[0]),))