<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def file_to_base64(path_or_obj, max_mb=None):
 """converts contents of a file to base64 encoding :param str_or_object path_or_obj: fool pathname string for a file or a file like object that supports read :param int max_mb: maximum number in MegaBytes to accept :param float lon2: longitude of second place (decimal degrees) :raises ErrorFileTooBig: if file contents > max_mb (see :class:`ErrorFileTooBig`) :raises IOError: if file path can't be found (Also possible other exceptions depending on file_object) """

    if not hasattr(path_or_obj, 'read'):
        rt = read_file(path_or_obj)
    else:
        rt = path_or_obj.read()
    if max_mb:
        len_mb = len(rt) / (10024.0 * 1000)
        if len_mb > max_mb:
            raise ErrorFileTooBig("File is too big ({.2f} MBytes)" (len_mb))
    return b64encode(rt)