def split_nest(in_str, sep=",", nest_pair="()", keep_nest=False):
    """split a string by sep, but don't touch seps in nested pairs"""
    res = []
    cur = []
    nesting = 0
    if nest_pair is None:
        nest_begin = None
        nest_end = None
    else:
        nest_begin = nest_pair[0]
        nest_end = nest_pair[1]
    # split string loop
    for c in in_str:
        if c == nest_end:
            nesting -= 1
        if nesting == 0:
            if c in sep:
                if len(cur) > 0:
                    res.append("".join(cur))
                    cur = []
            elif c not in (nest_begin, nest_end) or keep_nest:
                cur.append(c)
        else:
            cur.append(c)
        # adjust nesting
        if c == nest_begin:
            nesting += 1
    # final element
    if len(cur) > 0:
        res.append("".join(cur))
    return res