[issue18585] Add a text truncation function

Vajrasky Kok report at bugs.python.org
Wed Jul 31 08:11:41 CEST 2013


Vajrasky Kok added the comment:

Monsieur Pitrou, thanks for the explanation. Actually, IMHO I prefer, 'hello (...)' should be the minimum words we can use not '(...)' because '(...)' does not make any sense. But, anyway, it's your call. :)

Anyway, using your summarize2.patch:

>>> textwrap.summarize('hello      world!', width=6)
'(...)'

>>> textwrap.summarize('hello      world!', width=5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ethan/Documents/code/python/cpython/Lib/textwrap.py", line 378, in summarize
    return w.summarize(text, placeholder=placeholder)
  File "/home/ethan/Documents/code/python/cpython/Lib/textwrap.py", line 314, in summarize
    raise ValueError("placeholder too large for max width")
ValueError: placeholder too large for max width

Why? '(...)' is 5 characters only. I checked the patch and found out that the placeholder is ' (...)' (with space) and you compare the width with the placeholder.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18585>
_______________________________________


More information about the Python-bugs-list mailing list