format string to certain line width

elukkien at cmbi.ru.nl elukkien at cmbi.ru.nl
Wed Aug 13 08:13:20 EDT 2008


>>>> import textwrap
>>>> print textwrap.fill("HelloWorld", 2)
> He
> ll
> oW
> or
> ld
>
> Of course if your assertion that the string contains no spaces, tabs or
> newlines turns out to be incorrect this may not do what you wanted.

Thanks, i just found this myself and it works fine, but very slow...
The script without the wrapping takes 30 seconds, with wrapping 30
minutes. Is there not a more efficient way?
The perl syntax i posted is much faster.




More information about the Python-list mailing list