刘凡 9ff4d1d109 add S3,archive,truncate | 2 years ago | |
---|---|---|
.. | ||
.gitignore | 2 years ago | |
LICENSE | 2 years ago | |
MANIFEST | 2 years ago | |
README.md | 2 years ago | |
setup.py | 2 years ago | |
test.py | 2 years ago | |
truncate.py | 2 years ago |
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!