I am looking for a way to truncate a string in Python that will not cut off the string in the middle of a word.
For example:
Original: \"This is
Here's a slightly better version of the last line in Adam's solution:
return content[:length].rsplit(' ', 1)[0]+suffix
(This is slightly more efficient, and returns a more sensible result in the case there are no spaces in the front of the string.)