[Python-Dev] textwrap.py

Greg Ward gward@python.net
Sat, 8 Jun 2002 20:27:22 -0400


On 07 June 2002, Paul Prescod said:
> Greg Ward wrote:
> > 
> >...
> > 
> > Yeah, me too.  But there are an unbounded number of possible options
> > that people might insist on, and making these options instance
> > attributes seems vaguely friendly to subclasses to me. 
> 
> I don't follow. If I want a subclass then I need to instantiate it
> somehow. When I do, I'll call its constructor. I'll pass its constructor
> the keyword arguments that the subclass expects.

Umm, ignore my original argument.  I don't understand what I was talking
about, and I understand your rebuttal even less.  Let's accept the fact
that we're not communicating and drop it.

However, I *still* don't want to make all of TextWrapper's options
keyword arguments to the wrap() method, because 1) I'd be morally bound
to make them kwargs to the fill() method, and to the standalone wrap()
and fill() functions as well, which is a PITA; and 2) I think it's
useful to be able to encode your preferences in an object for multiple
wrapping jobs.

Compromise: the TextWrapper constructor now looks like this:

    def __init__ (self,
                  expand_tabs=True,
                  replace_whitespace=True,
                  fix_sentence_endings=False,
                  break_long_words=True):
        self.expand_tabs = expand_tabs
        self.replace_whitespace = replace_whitespace
        self.fix_sentence_endings = fix_sentence_endings
        self.break_long_words = break_long_words

Good enough?  I'm happy with it.

        Greg
-- 
Greg Ward - Unix geek                                   gward@python.net
http://starship.python.net/~gward/
Question authority!