Message143795
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. |
|
Date |
User |
Action |
Args |
2011-09-09 19:29:08 | terry.reedy | set | recipients:
+ terry.reedy, eric.araujo |
2011-09-09 19:29:08 | terry.reedy | set | messageid: <1315596548.05.0.304216160882.issue12914@psf.upfronthosting.co.za> |
2011-09-09 19:29:07 | terry.reedy | link | issue12914 messages |
2011-09-09 19:29:07 | terry.reedy | create | |
|