solvebio/utils/tabulate.py
def _align_column(strings, alignment, minwidth=0, has_invisible=True):
    """
    [string] -> [padded_string]

    >>> list(map(str,_align_column( \
        ["12.345", "-1234.5", "1.23", "1234.5", \
         "1e+234", "1.0e234"], "decimal")))
    ['   12.345  ', '-1234.5    ', '    1.23   ', \
     ' 1234.5    ', '    1e+234 ', '    1.0e234']

    """
    if alignment == "right":
        strings = [s.strip() for s in strings]
        padfn = _padleft
    elif alignment in "center":
        strings = [s.strip() for s in strings]
        padfn = _padboth
    elif alignment in "decimal":
        decimals = [_afterpoint(s) for s in strings]
        maxdecimals = max(decimals)
        strings = [s + (maxdecimals - decs) * " "
                   for s, decs in zip(strings, decimals)]
        padfn = _padleft
    else:
        strings = [s.strip() for s in strings]
        padfn = _padright

    if has_invisible:
        width_fn = _visible_width
    else:
        width_fn = len

    maxwidth = max(max(list(map(width_fn, strings))), minwidth)
    padded_strings = [padfn(maxwidth, s, has_invisible) for s in strings]
    return padded_strings
def _align_column(strings, alignment, minwidth=0, has_invisible=True):
    """
    [string] -> [padded_string]

    >>> list(map(str,_align_column( \
        ["12.345", "-1234.5", "1.23", "1234.5", \
         "1e+234", "1.0e234"], "decimal")))
    ['   12.345  ', '-1234.5    ', '    1.23   ', \
     ' 1234.5    ', '    1e+234 ', '    1.0e234']

    """
    if alignment == "right":
        strings = [s.strip() for s in strings]
        padfn = _padleft
    elif alignment in "center":
        strings = [s.strip() for s in strings]
        padfn = _padboth
    elif alignment in "decimal":
        decimals = [_afterpoint(s) for s in strings]
        maxdecimals = max(decimals)
        strings = [s + (maxdecimals - decs) * " "
                   for s, decs in zip(strings, decimals)]
        padfn = _padleft
    else:
        strings = [s.strip() for s in strings]
        padfn = _padright

    if has_invisible:
        width_fn = _visible_width
    else:
        width_fn = len

    maxwidth = max(max(list(map(width_fn, strings))), minwidth)
    padded_strings = [padfn(maxwidth, s, has_invisible) for s in strings]
    return padded_strings
def _align_column ( strings , alignment , minwidth = 0 , has_invisible = True ) : if alignment == "right" : strings = [ s . strip ( ) for s in strings ] padfn = _padleft elif alignment in "center" : strings = [ s . strip ( ) for s in strings ] padfn = _padboth elif alignment in "decimal" : decimals = [ _afterpoint ( s ) for s in strings ] maxdecimals = max ( decimals ) strings = [ s + ( maxdecimals - decs ) * " " for s , decs in zip ( strings , decimals ) ] padfn = _padleft else : strings = [ s . strip ( ) for s in strings ] padfn = _padright if has_invisible : width_fn = _visible_width else : width_fn = len maxwidth = max ( max ( list ( map ( width_fn , strings ) ) ) , minwidth ) padded_strings = [ padfn ( maxwidth , s , has_invisible ) for s in strings ] return padded_strings
[string] -> [padded_string]

    >>> list(map(str,_align_column( \
        ["12.345", "-1234.5", "1.23", "1234.5", \
         "1e+234", "1.0e234"], "decimal")))
    ['   12.345  ', '-1234.5    ', '    1.23   ', \
     ' 1234.5    ', '    1e+234 ', '    1.0e234']
[ string ] - > [ padded_string ]