[Python-Dev] textwrap wordsep_re

2005-02-21 Thread Karl Chen

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('aa 2005-02-21', 18)
produces:
aa 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('aa 2005-02-21', 18)
behaves better:
aa
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


[Python-Dev] textwrap.py wordsep_re

2005-02-22 Thread Karl Chen

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('aa 2005-02-21', 18)
produces:
aa 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('aa 2005-02-21', 18)
behaves better:
aa
2005-02-21


What do you think about changing the default wordsep_re?

-- 
Karl 2005-02-21 03:32
___
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


Re: [Python-Dev] textwrap.py wordsep_re

2005-02-24 Thread Karl Chen
> On 2005-02-24 05:04 PST, Greg Ward writes:

Greg> Post a patch to SF and assign it to me.  Make sure the
Greg> unit tests still pass, and add a new one that doesn't
Greg> pass without your fix.  Pester me mercilessly until I
Greg> act on it.  (I think your change is probably fine, but I
Greg> need more time to examine it than I have right now.)

I had already posted a patch on Aahz's advice.  I'll write a unit
test.

-- 
Karl 2005-02-24 13:18
___
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


Re: [Python-Dev] textwrap.py wordsep_re

2005-02-27 Thread Karl Chen
> On 2005-02-24 05:04 PST, Greg Ward writes:

Greg> Post a patch to SF and assign it to me.  Make sure the
Greg> unit tests still pass, and add a new one that doesn't
Greg> pass without your fix.

Done.  Patch id 1149508.

-- 
Karl 2005-02-27 10:29
___
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


[Python-Dev] list splicing

2005-09-18 Thread Karl Chen
Hi, has anybody considered adding something like this:
a = [1, 2]
[ 'x', *a, 'y']

as syntactic sugar for
a = [1, 2]
[ 'x' ] + a + [ 'y' ].

Notes:
- This is a common operation
- To me, the splicing form looks much better than the
  concatenation form
- It can be implemented more efficiently than a bunch of list
  concatenations
- This would be similar to the "apply" feature [ foo(*a) ].  The
  '*' operator is reminiscent of dereferencing operators in
  C-derived languages.  Alternatively it could be '@', like perl's
  implicit array splicing, and Lisp's ',@' in backquoted lists.
- (I know "splicing" traditionally refers to something else in
  Python, but other languages refer to this as splicing, and the
  English definition of "splice" applies better to this.)

-- 
Karl 2005-09-18 18:26

___
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