File indexing completed on 2025-01-19 03:59:54
0001 from contextlib import contextmanager 0002 0003 0004 @contextmanager 0005 def open_file(file_or_name, mode="w"): 0006 if isinstance(file_or_name, str): 0007 obj = open(file_or_name, mode) 0008 try: 0009 yield obj 0010 finally: 0011 obj.close() 0012 else: 0013 yield file_or_name