<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _write_export(export, file_obj=None):
 """ Write a string to a file. If file_obj isn't specified, return the string Parameters --------- export: a string of the export data file_obj: a file-like object or a filename """


    if file_obj is None:
        return export

    if hasattr(file_obj, 'write'):
        out_file = file_obj
    else:
        out_file = open(file_obj, 'wb')
    try:
        out_file.write(export)
    except TypeError:
        out_file.write(export.encode('utf-8'))

    out_file.close()

    return export