Hi, 

textwrap.fill() is awesome.

Except when the string to wrap contains dates -- which I would
like not to be broken.  In general I think wordsep_re can be
smarter about what it decides are hyphenated words.

For example, this code:
    print textwrap.fill('aaaaaaaaaa 2005-02-21', 18)
produces:
    aaaaaaaaaa 2005-
    02-21

A slightly tweaked wordsep_re:
    textwrap.TextWrapper.wordsep_re = \
        re.compile(r'(\s+|'                  # any whitespace
                   r'[^\s\w]*\w+[a-zA-Z]-(?=[a-zA-Z]\w+)|' # hyphenated words
                   r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))')   # em-dash
    print textwrap.fill('aaaaaaaaaa 2005-02-21', 18)
behaves better:
    aaaaaaaaaa
    2005-02-21


What do you think about changing the default wordsep_re?

-- 
Karl 2005-02-21 17:39

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to