def shorten_string(string, max_width):
 string_len = len(string)
 if (string_len <= max_width):
  return string
 visible = ((max_width - 16) - int(log10(string_len)))
 if (not isinstance(string, unistr)):
  visstring = unistr(string[:visible], errors='ignore')
 else:
  visstring = string[:visible]
 return u''.join((visstring, u'...(and ', unistr((string_len - visible)), u' more)'))

def shorten_string ( string , max_width ) : string_len = len ( string ) if ( string_len <= max_width ) : return string visible = ( ( max_width - 16 ) - int ( log10 ( string_len ) ) ) if ( not isinstance ( string , unistr ) ) : visstring = unistr ( string [ : visible ] , errors = 'ignore' ) else : visstring = string [ : visible ] return u'' . join ( ( visstring , u'...(and ' , unistr ( ( string_len - visible ) ) , u' more)' ) )
make limited length string in form: "the string is very lo .