def serialize_file(struct, path, format=None, encoding='<STR_LIT:utf-8>'):
try:<EOL><INDENT>with open(path, '<STR_LIT:wb>') as f:<EOL><INDENT>return serialize(struct, format, f, encoding)<EOL><DEDENT><DEDENT>except EnvironmentError as e:<EOL><INDENT>raise AnyMarkupError(e, traceback.format_exc())<EOL><DEDENT>
A convenience wrapper of serialize, which accepts path of file to serialize to.

    Args:
        struct: structure (dict or list) with unicode members to serialize; note that list
            can only be serialized to json
        path: path of the file to serialize to
        format: override markup format to serialize structure as (taken from filename
            by default)
        encoding: encoding to use when serializing, defaults to utf-8
    Returns:
        number of bytes written
    Raises:
        AnyMarkupError if a problem occurs while serializing