def str_before_last(src, sub):
    """Return a substring from the beginning of the string to the last occurrence of the substring sub"""
    idx = src.rfind(sub)
    return src[:idx] if idx >= 0 else ''
