def smart_split(str, sep, lim, default=""):
    """
    Split into at least lim elements using default value if needed.
    """
    s = str.split(sep, lim - 1)
    if len(s) < lim:
        s.extend([default] * (lim - len(s)))
    return s