textwrap.fill algorithm? (Difference with vim)

Peter Otten __peter__ at web.de
Sat Apr 22 14:33:56 EDT 2017


Matěj Cepl wrote:

> On 2017-04-22, 01:01 GMT, Gregory Ewing wrote:
>> I don't know what vim is doing, but if you tell Python you
>> want lines no longer than 65 characters, it takes you at
>> your word.
> 
> Oh, I’ve got it. textwrap.fill() (only in Python 2.*?) completely
> sucks with bytes, because of course it counts every byte as
> separate character for purpose of counting. All the text must be
> converted into unicode. It would be probably nice, if the
> textwrap documentation mentioned it.

Yes, the documentation should warn about the limitations of textwrap's 
notion of width -- but still, the line you complained about

        10        20        30        40        50        60        70
123456789+123456789+123456789+123456789+123456789+123456789+123456789+12
It is necessary to issue this caution, for the popular mind has grown so

contains only ascii, so whether you count bytes or characters -- it's always 
72, not 65.



More information about the Python-list mailing list