It is pretty easy to truncate a string in Python. For example:
>>> ================================ RESTART ================================
>>> s = 'Some simple string. This should be cut off.'
>>> print s[0:28]
Some simple string. This sho
>>>
The problem is that it isn’t the nicest looking thing in the world…wouldn’t this be better:
>>> ================================ RESTART ================================
>>>
>>> from trunc import *
>>> s = 'Some simple string. This should be cut off.'
>>> print trunc(s,max_pos=25)
Some simple string...
>>>
This simple little function attempts to make a better looking, but shorter, string out of your input string. I use it to shorten large text fields from databases into smaller chunks suitable for use in summary tables.