|
|
%!s(int64=3) %!d(string=hai) anos | |
|---|---|---|
| .. | ||
| .gitignore | %!s(int64=3) %!d(string=hai) anos | |
| LICENSE | %!s(int64=3) %!d(string=hai) anos | |
| MANIFEST | %!s(int64=3) %!d(string=hai) anos | |
| README.md | %!s(int64=3) %!d(string=hai) anos | |
| setup.py | %!s(int64=3) %!d(string=hai) anos | |
| test.py | %!s(int64=3) %!d(string=hai) anos | |
| truncate.py | %!s(int64=3) %!d(string=hai) anos | |
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!