A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-February/051749.html below:

[Python-Dev] textwrap.py wordsep_re

[Python-Dev] textwrap.py wordsep_re [Python-Dev] textwrap.py wordsep_reKarl Chen quarl at cs.berkeley.edu
Mon Feb 21 12:39:41 CET 2005
Hi, 

textwrap.fill() is awesome.

Except when the string to wrap contains dates -- which I would
like not to be filled.  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 03:32
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4