Created
April 18, 2012 06:51
-
-
Save aj-justo/2411567 to your computer and use it in GitHub Desktop.
safe truncate in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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