def dump_board_to(board, filename, style='verbose'): """Dump the board into the given filename, attempting to recognize the format by the file extension.""" import board.formats as formats fmt = formats.format_for(filename) f = open(filename, 'w') board.dump(f, fmt, style=style) f.close()
def load_board_from(filename): """Load the board from the given filename, attempting to recognize the format by the file extension.""" import board.formats as formats fmt = formats.format_for(filename) board = Board((1, 1)) f = open(filename, 'r') board.load(f, fmt) f.close() return board