def truncate(string, length, ellipsis="…"):
    """ Truncate a string to a length, ending with '...' if it overflows """
    if len(string) > length:
        return string[: length - len(ellipsis)] + ellipsis
    return string
def truncate ( string , length , ellipsis = "…" ) : if len ( string ) > length : return string [ : length - len ( ellipsis ) ] + ellipsis return string
Truncate a string to a length, ending with '...' if it overflows