[New-bugs-announce] [issue15492] textwrap.wrap expand_tabs does not behave as expected

Chris Jerdonek report at bugs.python.org
Sun Jul 29 23:11:57 CEST 2012


New submission from Chris Jerdonek:

While working on issue 1859, I noticed that textwrap.wrap()'s tab expansion does not seem to behave sensibly.

In particular, the documentation says, "If expand_tabs is true, then all tab characters in text will be expanded to zero or more spaces, *depending on the current column* and the given tab size."

The problem is that tab expansion is done as the first stage (and in particular, before wrapping), which means that "the current column" is no longer current after wrapping.  This leads to results like--

from textwrap import wrap

text = ("a\tb "
        "a\tb")

lines = wrap(text, width=5, tabsize=4)
for line in lines:
    print(repr(line))

Output:
'a   b'
'a b'

One would expect tab expansion to occur after (or while) wrapping, so that tab stops line up in the wrapped output.

----------
messages: 166815
nosy: cjerdonek
priority: normal
severity: normal
status: open
title: textwrap.wrap expand_tabs does not behave as expected

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15492>
_______________________________________


More information about the New-bugs-announce mailing list