def intfmt(maxval, fill=" "):
    """
    returns the appropriate format string for integers that can go up to
    maximum value maxvalue, inclusive.
    """
    vallen = len(str(maxval))
    return "{:" + fill + str(vallen) + "d}"