Terry J. Reedy <[email protected]> added the comment:
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.
----------
nosy: +terry.reedy
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue12914>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com