(obj, dict_mode=False)
Recursively convert iterated object (list/tuple/dict/set) to string.
Recursively convert iterated object (list/tuple/dict/set) to string.
Recursively convert iterated object ( list / tuple / dict / set ) to string .
def ostr(obj, dict_mode=False):
    """
    Recursively convert iterated object (list/tuple/dict/set) to string.
    """
    def ostr_rec(obj, dict_mode):
        global ostr_s
        if isinstance(obj, tuple):
            if len(obj) == 0:
                ostr_s += '(),'
            else:
                ostr_s += '('
                for obj_i in obj:
                    ostr_rec(obj_i, dict_mode)
                ostr_s = ostr_s[:-1] + '),'
        elif isinstance(obj, list):
            if len(obj) == 0:
                ostr_s += '[],'
            else:
                ostr_s += '['
                for obj_i in obj:
                    ostr_rec(obj_i, dict_mode)
                ostr_s = ostr_s[:-1] + '],'
        elif isinstance(obj, dict):
            if dict_mode:
                ostr_s += '\n'
                for key in obj.keys():
                    ostr_rec(key, dict_mode)
                    if ostr_s[-1] == ',':
                        ostr_s = ostr_s[:-1]
                    ostr_s += ' -> '
                    ostr_rec(obj[key], dict_mode)
                    if ostr_s[-1] == ',':
                        ostr_s = ostr_s[:-1]
                    ostr_s += '\n'
            else:
                ostr_s += '{'
                for key in obj.keys():
                    ostr_rec(key, dict_mode)
                    if ostr_s[-1] == ',':
                        ostr_s = ostr_s[:-1]
                    ostr_s += ':'
                    ostr_rec(obj[key], dict_mode)
                ostr_s = ostr_s[:-1] + '} '
        elif isinstance(obj, set):
            tmp_obj = list(obj)
            ostr_s += '{'
            for obj_i in tmp_obj:
                ostr_rec(obj_i, dict_mode)
            ostr_s = ostr_s[:-1] + '},'
        else:
            ostr_s += str(obj) + ','
        return
    global ostr_s
    ostr_s = ''
    if isinstance(obj, (tuple, list, dict, set)):
        ostr_rec(obj, dict_mode)
        return ostr_s[:-1]
    else:
        return str(obj)
def ostr ( obj , dict_mode = False ) : def ostr_rec ( obj , dict_mode ) : global ostr_s if isinstance ( obj , tuple ) : if len ( obj ) == 0 : ostr_s += '(),' else : ostr_s += '(' for obj_i in obj : ostr_rec ( obj_i , dict_mode ) ostr_s = ostr_s [ : - 1 ] + '),' elif isinstance ( obj , list ) : if len ( obj ) == 0 : ostr_s += '[],' else : ostr_s += '[' for obj_i in obj : ostr_rec ( obj_i , dict_mode ) ostr_s = ostr_s [ : - 1 ] + '],' elif isinstance ( obj , dict ) : if dict_mode : ostr_s += '\n' for key in obj . keys ( ) : ostr_rec ( key , dict_mode ) if ostr_s [ - 1 ] == ',' : ostr_s = ostr_s [ : - 1 ] ostr_s += ' -> ' ostr_rec ( obj [ key ] , dict_mode ) if ostr_s [ - 1 ] == ',' : ostr_s = ostr_s [ : - 1 ] ostr_s += '\n' else : ostr_s += '{' for key in obj . keys ( ) : ostr_rec ( key , dict_mode ) if ostr_s [ - 1 ] == ',' : ostr_s = ostr_s [ : - 1 ] ostr_s += ':' ostr_rec ( obj [ key ] , dict_mode ) ostr_s = ostr_s [ : - 1 ] + '} ' elif isinstance ( obj , set ) : tmp_obj = list ( obj ) ostr_s += '{' for obj_i in tmp_obj : ostr_rec ( obj_i , dict_mode ) ostr_s = ostr_s [ : - 1 ] + '},' else : ostr_s += str ( obj ) + ',' return global ostr_s ostr_s = '' if isinstance ( obj , ( tuple , list , dict , set ) ) : ostr_rec ( obj , dict_mode ) return ostr_s [ : - 1 ] else : return str ( obj )