def for_format(filename, format=None, writable=False, prefix_dir=None):
    """
    Create a MeshIO instance for file `filename` with forced `format`.

    Parameters
    ----------
    filename : str
        The name of the mesh file.
    format : str
        One of supported formats. If None,
        :func:`MeshIO.any_from_filename()` is called instead.
    writable : bool
        If True, verify that the mesh format is writable.
    prefix_dir : str
        The directory name to prepend to `filename`.

    Returns
    -------
    io : MeshIO subclass instance
        The MeshIO subclass instance corresponding to the `format`.
    """
    ext = op.splitext(filename)[1].lower()
    try:
        _format = supported_formats[ext]
    except KeyError:
        _format = None

    format = get_default(format, _format)

    if format is None:
        io = MeshIO.any_from_filename(filename, prefix_dir=prefix_dir)

    else:
        if not isinstance(format, basestr):
            raise ValueError('ambigous suffix! (%s -> %s)' % (ext, format))

        if format not in io_table:
            raise ValueError('unknown output mesh format! (%s)' % format)

        if writable and ('w' not in supported_capabilities[format]):
            output_writable_meshes()
            msg = 'write support not implemented for output mesh format "%s",' \
                  ' see above!' \
                  % format
            raise ValueError(msg)

        if prefix_dir is not None:
            filename = op.normpath(op.join(prefix_dir, filename))

        io = io_table[format](filename)

    return io
def for_format ( filename , format = None , writable = False , prefix_dir = None ) : ext = op . splitext ( filename ) [ 1 ] . lower ( ) try : _format = supported_formats [ ext ] except KeyError : _format = None format = get_default ( format , _format ) if format is None : io = MeshIO . any_from_filename ( filename , prefix_dir = prefix_dir ) else : if not isinstance ( format , basestr ) : raise ValueError ( 'ambigous suffix! (%s -> %s)' % ( ext , format ) ) if format not in io_table : raise ValueError ( 'unknown output mesh format! (%s)' % format ) if writable and ( 'w' not in supported_capabilities [ format ] ) : output_writable_meshes ( ) msg = 'write support not implemented for output mesh format "%s",' ' see above!' % format raise ValueError ( msg ) if prefix_dir is not None : filename = op . normpath ( op . join ( prefix_dir , filename ) ) io = io_table [ format ] ( filename ) return io
Create a MeshIO instance for file `filename` with forced `format`.

    Parameters
    ----------
    filename : str
        The name of the mesh file.
    format : str
        One of supported formats. If None,
        :func:`MeshIO.any_from_filename()` is called instead.
    writable : bool
        If True, verify that the mesh format is writable.
    prefix_dir : str
        The directory name to prepend to `filename`.

    Returns
    -------
    io : MeshIO subclass instance
        The MeshIO subclass instance corresponding to the `format`.