To re or not to re ... ( word wrap function?)

Boyd Roberts boyd at insultant.net
Fri Sep 21 22:30:27 EDT 2001


> "Ignacio Vazquez-Abrams" <ignacio at openservices.net> a écrit dans le message news:
> mailman.1001111905.15419.python-list at python.org...
> > Yup. The following will do an entire document at once:
> >
> > ---
> > def wordwrap(text, width):
>
> i hope you have small documents or a _large_ amount or ram;  your
> solution will not scale.
>
> ...
>
> Well, I think "will" was the wrong word. I should have said "can".

I think 'scale' was the wrong word.  I should have written 'work'.

>>> t = 'this is some text that will slop'
>>> n = 'this is the next line in the file'
>>> print wordwrap(t, 10)
this is
some text
that will
slop
>>> print wordwrap(n, 10)
this is
the next
line in
the file
>>>

so:

    It is entirely possible to feed the function one line or a subset
    of lines at a time and it will still perform as expected.

it will work on a subset of cases, but not in the general case.

you would have to enclose it in a loop and do more grotesque
string mangling, if you don't want to run out of memory and
for it to finish in a reasonable time.






More information about the Python-list mailing list