README.md 389 B

truncate

truncate string in python

##Code

import sys

def truncate(str, limit, ellipsis='...'): 
    return str[:limit] + ellipsis if len(str) > limit else str 

sys.modules[__name__] = truncate

##Install

$ pip install trunkate

##Usage

import truncate

truncate('Hello world!', 4)
# Hell...

truncate('Hello world!', 100)
# Hello world!