def export_to_csv(<EOL>table,<EOL>filename_or_fobj=None,<EOL>encoding="<STR_LIT:utf-8>",<EOL>dialect=unicodecsv.excel,<EOL>batch_size=<NUM_LIT:100>,<EOL>callback=None,<EOL>*args,<EOL>**kwargs<EOL>):
<EOL>return_data, should_close = False, None<EOL>if filename_or_fobj is None:<EOL><INDENT>filename_or_fobj = BytesIO()<EOL>return_data = should_close = True<EOL><DEDENT>source = Source.from_file(<EOL>filename_or_fobj,<EOL>plugin_name="<STR_LIT>",<EOL>mode="<STR_LIT:wb>",<EOL>encoding=encoding,<EOL>should_close=should_close,<EOL>)<EOL>writer = unicodecsv.writer(source.fobj, encoding=encoding, dialect=dialect)<EOL>if callback is None:<EOL><INDENT>for batch in ipartition(serialize(table, *args, **kwargs), batch_size):<EOL><INDENT>writer.writerows(batch)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>serialized = serialize(table, *args, **kwargs)<EOL>writer.writerow(next(serialized))  <EOL>total = <NUM_LIT:0><EOL>for batch in ipartition(serialized, batch_size):<EOL><INDENT>writer.writerows(batch)<EOL>total += len(batch)<EOL>callback(total)<EOL><DEDENT><DEDENT>if return_data:<EOL><INDENT>source.fobj.seek(<NUM_LIT:0>)<EOL>result = source.fobj.read()<EOL><DEDENT>else:<EOL><INDENT>source.fobj.flush()<EOL>result = source.fobj<EOL><DEDENT>if source.should_close:<EOL><INDENT>source.fobj.close()<EOL><DEDENT>return result<EOL>
Export a `rows.Table` to a CSV file.


    If a file-like object is provided it MUST be in binary mode, like in
    `open(filename, mode='wb')`.
    If not filename/fobj is provided, the function returns a string with CSV
    contents.