import re


def pyformat_from_cformat(s, math_text=False):
    """Convert string format specifier from C style to Python style,
    which could be used by `str.format()` function.
    """
    islog = False
    r = re.match('(.*)%(.*)', s)
    if r is None:
        return None, None
    prefix, specifier = r.group(1), r.group(2)
    if 'n' in specifier:  # log scale
        islog = True
        if prefix != '':
            fmt = prefix + '{{{:' + 'd' + '}}}'
        else:
            fmt = '{:' + 'd' + '}'
    else:
        fmt = prefix + '{:' + specifier + '}'
    if math_text:
        fmt = '${}$'.format(fmt)
    return fmt, islog