Skip to content

Instantly share code, notes, and snippets.

@aj-justo
Created April 18, 2012 06:51
Show Gist options
  • Save aj-justo/2411567 to your computer and use it in GitHub Desktop.
Save aj-justo/2411567 to your computer and use it in GitHub Desktop.
safe truncate in python
def truncate_str(mstr, length):
if length > len(mstr) : return mstr
return mstr[:length].rpartition(' ')[0] + ' ...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment