(game, filename, *args, **kwargs)
Write the game data to a file, based on a filename.

    If filename ends with .p8.png, the output is a .p8.png file. If the
    output file exists, its label is reused, otherwise an empty label is
    used. The label can be overridden by the caller with the
    'label_fname' argument.

    Args:
        game: The game to save.
        filename: The filename.
Write the game data to a file, based on a filename.
Write the game data to a file based on a filename .
def to_file(game, filename, *args, **kwargs):
    """Write the game data to a file, based on a filename.

    If filename ends with .p8.png, the output is a .p8.png file. If the
    output file exists, its label is reused, otherwise an empty label is
    used. The label can be overridden by the caller with the
    'label_fname' argument.

    Args:
        game: The game to save.
        filename: The filename.
    """
    fmt = formatter_for_filename(filename=filename)
    file_args = {'mode': 'wb+'}
    with tempfile.TemporaryFile(**file_args) as outfh:
        if kwargs.get('label_fname', None) is None:
            if os.path.exists(filename):
                kwargs['label_fname'] = filename
        fmt.to_file(game, outfh, filename=filename, *args, **kwargs)
        outfh.seek(0)
        with open(filename, **file_args) as finalfh:
            finalfh.write(outfh.read())
def to_file ( game , filename , * args , * * kwargs ) : fmt = formatter_for_filename ( filename = filename ) file_args = { 'mode' : 'wb+' } with tempfile . TemporaryFile ( * * file_args ) as outfh : if kwargs . get ( 'label_fname' , None ) is None : if os . path . exists ( filename ) : kwargs [ 'label_fname' ] = filename fmt . to_file ( game , outfh , filename = filename , * args , * * kwargs ) outfh . seek ( 0 ) with open ( filename , * * file_args ) as finalfh : finalfh . write ( outfh . read ( ) )