textwrap.fill algorithm? (Difference with vim)

Peter Otten __peter__ at web.de
Fri Apr 21 17:54:07 EDT 2017


Matěj Cepl wrote:

> I have a gedit Python plugin which should do line wrap using
> textwrap.fill() function.  However, even when I have set the
> length of line to the same number as in vim (65), the result is
> substantially different (textwrap.fill paragraphs are
> significantly narrower). See for example this diff (removed
> lines are wrapped by vim, added by textwrap.fill-based plugin).
> 
> Why cannot textwrap.fill get those words “grown so” to the first
> line of the wrapped text? Any ideas about the difference in the
> algorithms for line-wrapping in vim and in textwrapper.fill?

It's not the algorithm, it's the width. Try textwrap.fill(text, 72).




More information about the Python-list mailing list