(f, val, grouping=False, monetary=False)
return new_f % val
Formats a string in the same way that the % formatting would use,
    but takes the current locale into account.

    Grouping is applied if the third parameter is true.
    Conversion uses monetary thousands separator and grouping strings if
    forth parameter monetary is true.
Formats a string in the same way that the % formatting would use,
    but takes the current locale into account.
Formats a string in the same way that the % formatting would use but takes the current locale into account .
def format_string(f, val, grouping=False, monetary=False):
    """Formats a string in the same way that the % formatting would use,
    but takes the current locale into account.

    Grouping is applied if the third parameter is true.
    Conversion uses monetary thousands separator and grouping strings if
    forth parameter monetary is true."""
    percents = list(_percent_re.finditer(f))
    new_f = _percent_re.sub('%s', f)

    if isinstance(val, _collections_abc.Mapping):
        new_val = []
        for perc in percents:
            if perc.group()[-1]=='%':
                new_val.append('%')
            else:
                new_val.append(_format(perc.group(), val, grouping, monetary))
    else:
        if not isinstance(val, tuple):
            val = (val,)
        new_val = []
        i = 0
        for perc in percents:
            if perc.group()[-1]=='%':
                new_val.append('%')
            else:
                starcount = perc.group('modifiers').count('*')
                new_val.append(_format(perc.group(),
                                      val[i],
                                      grouping,
                                      monetary,
                                      *val[i+1:i+1+starcount]))
                i += (1 + starcount)
    val = tuple(new_val)

    return new_f % val
def format_string ( f , val , grouping = False , monetary = False ) : percents = list ( _percent_re . finditer ( f ) ) new_f = _percent_re . sub ( '%s' , f ) if isinstance ( val , _collections_abc . Mapping ) : new_val = [ ] for perc in percents : if perc . group ( ) [ - 1 ] == '%' : new_val . append ( '%' ) else : new_val . append ( _format ( perc . group ( ) , val , grouping , monetary ) ) else : if not isinstance ( val , tuple ) : val = ( val , ) new_val = [ ] i = 0 for perc in percents : if perc . group ( ) [ - 1 ] == '%' : new_val . append ( '%' ) else : starcount = perc . group ( 'modifiers' ) . count ( '*' ) new_val . append ( _format ( perc . group ( ) , val [ i ] , grouping , monetary , * val [ i + 1 : i + 1 + starcount ] ) ) i += ( 1 + starcount ) val = tuple ( new_val ) return new_f % val