def truncatechars(value, arg):
 try:
  length = int(arg)
 except ValueError:
  return value
 if (len(value) > length):
  return (value[:(length - 3)] + '...')
 return value

def truncatechars ( value , arg ) : try : length = int ( arg ) except ValueError : return value if ( len ( value ) > length ) : return ( value [ : ( length - 3 ) ] + '...' ) return value
truncates a string after a certain number of characters .