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.
A few thoughts: * no one has ever made a request for this * different people may want to do it in different ways (the formulas are hard-wired). * the '...' connector is hardwired (perhaps ' ... ' would look less odd). * we should have a preference for keeping APIs small (more to learn and remember) * this is dirt simple string processing and not hard for people to roll their own if the need arises * if the API were to be expanded, perhaps it should be as a part of a focuses, thoughtful effort to provide a more generic set of text formatting transformations perhaps modeled on deep experiences with similar modules in other languages. (as opposed to piecemeal additions that weren't designed with a coherent vision).
This pretty well summarizes my vague feelings. I originally used a size 30 in my example, getting 'This sentence...made available' and then realized that it was a complete accident that I got complete words. If anything were made publicly available, I might like a more sophisticated algorithm. I think other things in pydoc are more worth of consideration. So I am now -.5 or more and would not mind closing this one of the four new pydoc exposure issues.
> if the API were to be expanded, perhaps it should be as a part of a > focuse[d], thoughtful effort to provide a more generic set of text > formatting transformations perhaps modeled on deep experiences with > similar modules in other languages. (as opposed to piecemeal additions > that weren't designed with a coherent vision). That’s a very strong point. Thanks for the opinions.