def shorten(s, width=80):
    """
    >>> shorten('a very very very very long sentence', 20)
    'a very very ..(23)..'
    """
    if not isinstance(s, str):
        s = str(s)
    length = len(s)
    if length < width:
        return s
    cut_length = length - width + 6
    x = len(str(cut_length))
    cut_length += x
    if x != len(str(cut_length)):
        cut_length += 1
    end_pos = length - cut_length
    return s[:end_pos] + '..(%d)..' % cut_length
