[Python-Dev] Re: Where to put wrap_text()?
Sat, 1 Jun 2002 18:05:29 -0400
On 01 June 2002, Fran?ois Pinard said:
> One thing that I would love to have available in Python is a function able
> to wrap text using Knuth's filling algorithm. GNU `fmt' does it, and it
> is _so_ better than dumb refilling, in my eyes at least, that I managed
> so Emacs own filling algorithm is short-circuited with an external call
> (I do not mind the small fraction of a second it takes).
Damn, I had no idea there was a body of computer science (however small)
devoted to the art of filling text. Trust Knuth to be there first. Do
you have a reference for this algorithm apart from GNU fmt's source
code? Google'ing for "knuth text fill algorithm" was unhelpful, ditto
Anyways, despite being warned just today on the conceptual/philosophical
danger of classes whose names end in "-er" , I'm leaning towards a
TextWrapper class, so that everyone may impose their desires through
subclassing. I'll start with my simple naive text-wrapping algorithm,
and then we can see who wants to contribute fancy/clever algorithms to
> Also, is there some existing module in which `wraptext' would fit nicely?
> That might be better than creating a new module for not many functions.
Not if it grows to accomodate Optik/OptionParser, Mailman, regrtest,
 objects should *be*, not *do*, and class names like HelpFormatter
and TextWrapper are impositions of procedural abstraction onto
OOP. It's something to be aware of, but still a useful idiom
Greg Ward - Unix geek firstname.lastname@example.org
No problem is so formidable that you can't just walk away from it.