This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients eric.araujo, terry.reedy
Date 2011-09-09.19:29:07
SpamBayes Score 0.00011686051
Marked as misclassified No
Message-id <1315596548.05.0.304216160882.issue12914@psf.upfronthosting.co.za>
In-reply-to
Content
It is already available:
>>> import pydoc
>>> pydoc.cram('This sentence is too long to fit the space I have made available', 28)
'This sentenc...ade available'

def cram(text, maxlen):
    """Omit part of a string if needed to make it fit in a maximum length."""
    if len(text) > maxlen:
        pre = max(0, (maxlen-3)//2)
        post = max(0, maxlen-3-pre)
        return text[:pre] + '...' + text[len(text)-post:]
    return text

It could be documented in place, or moved and imported into pydoc. I am +0 at the moment.
History
Date User Action Args
2011-09-09 19:29:08terry.reedysetrecipients: + terry.reedy, eric.araujo
2011-09-09 19:29:08terry.reedysetmessageid: <1315596548.05.0.304216160882.issue12914@psf.upfronthosting.co.za>
2011-09-09 19:29:07terry.reedylinkissue12914 messages
2011-09-09 19:29:07terry.reedycreate