Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue1859] textwrap doesn't linebreak on "\n"

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 19, 2009, 5:52 AM

Post #1 of 9 (365 views)
Permalink
[issue1859] textwrap doesn't linebreak on "\n"

Tom Lynn <tlynn [at] users> added the comment:

This bug should be re-opened, since there is definitely a bug here.
I think the patch was incorrectly rejected.

If I can expand palfrey's example:

from textwrap import *
T = TextWrapper(replace_whitespace=False, width=75)
text = '''\
aaaaa aaaaa aaaaa aaaaa aaaaa
bbbbb bbbbb bbbbb bbbbb bbbbb
ccccc ccccc ccccc ccccc ccccc
ddddd ddddd ddddd ddddd ddddd
eeeee eeeee eeeee eeeee eeeee'''
for line in T.wrap(text): print line

Python 2.5 textwrap turns it into:

aaaaa aaaaa aaaaa aaaaa aaaaa
bbbbb bbbbb bbbbb bbbbb bbbbb
ccccc ccccc
ccccc ccccc ccccc
ddddd ddddd ddddd ddddd ddddd
eeeee eeeee eeeee eeeee
eeeee

That can't be right. palfrey's patch leaves the input unchanged, which
seems correct to me. I think Guido guessed wrong here: the docs for
replace_whitespace say:

If true, each whitespace character (as defined by string.whitespace)
remaining after tab expansion will be replaced by a single space

The text should therefore not be reflowed in this case since
replace_whitespace=False. palfrey's patch seems correct to me.

It can be made to reflow to the full width by editing palfrey's patch,
but that would disagree with the docs and break code.

----------
nosy: +tlynn

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 19, 2009, 7:56 AM

Post #2 of 9 (341 views)
Permalink
[issue1859] textwrap doesn't linebreak on "\n" [In reply to]

Guido van Rossum <guido [at] python> added the comment:

I think the code originally wasn't meant to support this feature (honor
embedded newlines when replace_whitespace=False). I'm thinking that we
could add it though. Maybe Mark is interested in getting this into 2.7
and 3.2? I imagine it needs a new unittest too.

----------
resolution: rejected ->
status: closed -> open

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 20, 2009, 6:17 AM

Post #3 of 9 (337 views)
Permalink
[issue1859] textwrap doesn't linebreak on "\n" [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

I'll take a look.

----------
assignee: -> mark.dickinson
priority: -> normal
versions: +Python 2.6, Python 2.7, Python 3.1, Python 3.2 -Python 2.4, Python 2.5

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 20, 2009, 12:38 PM

Post #4 of 9 (337 views)
Permalink
[issue1859] textwrap doesn't linebreak on "\n" [In reply to]

Terry J. Reedy <tjreedy [at] udel> added the comment:

I agree that if newlines in the text are left in, they should reset the
characters in line count to 0 the same as inserted newlines.

----------
nosy: +tjreedy

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 28, 2009, 10:33 AM

Post #5 of 9 (279 views)
Permalink
[issue1859] textwrap doesn't linebreak on "\n" [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

I notice that Greg Ward just resurfaced on the issue tracker (issue 6454).
:)

Greg, any comment on this issue?

----------
nosy: +gward
stage: -> test needed
type: behavior -> feature request
versions: -Python 2.6, Python 3.1

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 28, 2009, 10:47 AM

Post #6 of 9 (278 views)
Permalink
[issue1859] textwrap doesn't linebreak on "\n" [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

The current patch is too simple: it fails if lines end with ' \n', for
example. The simplest way to make this work may be to put each '\n' into
its own chunk.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 28, 2009, 2:11 PM

Post #7 of 9 (277 views)
Permalink
[issue1859] textwrap doesn't linebreak on "\n" [In reply to]

Greg Ward <greg [at] gerg> added the comment:

> Greg, any comment on this issue?

Yes, two:

1) textwrap does not handle paragraphs or paragraph breaks in any way.
That was a deliberate limitation to keep the code from getting any
hairier. People have complained about this in the past, and I have
studiously ignored such complaints. The standard answer is that you
should break your text into paragraphs and then feed those paragraphs
individually to a TextWrapper. But this does not look like that old
complaint.

2) Test, test, test. In case you hadn't already noticed, this is a
hairy piece of code. It's also a poster child for unit testing. Any
change should IMHO be accompanied by lots of new tests.

No wait, make that *three* comments:

3) I agree with tlynn that the example in msg95469 looks *awfully*
fishy. But I don't remember enough of the details to say what's likely
to be broken. That's probably your first test case right there.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 29, 2009, 10:58 PM

Post #8 of 9 (268 views)
Permalink
[issue1859] textwrap doesn't linebreak on "\n" [In reply to]

Phillip M. Feldman <pfeldman [at] verizon> added the comment:

As a temporary workaround, you can use the `wrap` function in my strnum
module (http://pypi.python.org/pypi/strnum/2.4).

Phillip

----------
nosy: +pfeldman [at] verizon

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Dec 7, 2009, 10:51 AM

Post #9 of 9 (238 views)
Permalink
[issue1859] textwrap doesn't linebreak on "\n" [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

Thanks for the feedback, Greg!

I'm afraid I'm unassigning this; I don't have time for it right now, and
I'm not sure I'm the right person to do this anyway.

One problem that I was having when I looked at this: I don't think I
understand what the intended use of replace_whitespace=False is in the
first place. Given that a typical piece of (English) text only contains
the ' ', '\t' ad '\n' whitespace characters, if expand_tabs is True (the
default), then it seems that newline characters are the only ones affected
by replace_whitespace=False.

How is replace_whitespace=False expected to be used currently?

----------
assignee: mark.dickinson ->

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.