def shorten(text, width, suffix='...'):
    """Truncate the given text to fit in the given width."""
    if len(text) <= width:
        return text
    if width > len(suffix):
        return text[:width-len(suffix)] + suffix
    if width >= 0:
        return suffix[len(suffix)-width:]
    raise ValueError('width must be equal or greater than 0')
Truncate the given text to fit in the given width.
stackoverflow/venv/lib/python3.6/site-packages/parsel/utils.py