469,890 Members | 1,454 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

question about the textwrap module

TP
Hi everybody,

Recently, I have tried to improve the look of the printed text in command
line. For this, I was compelled to remove redundant spaces in strings,
because in my scripts, often the strings are spreading on several lines.

For example, "aaa bbb" had to be transformed in "aaa bbb".
I have coded some simple functions to do that.

Today, by examining Python documentation, I have found an interesting
module:

http://www.python.org/doc/2.5.2/lib/...-textwrap.html

But, I haven't found any way to do my redundant space deletion with this
module? Am I right?

Thanks

Julien

--
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
Oct 27 '08 #1
3 1109
En Mon, 27 Oct 2008 20:50:08 -0200, TP <Tr**********@paralleles.invalid>
escribió:
Recently, I have tried to improve the look of the printed text in command
line. For this, I was compelled to remove redundant spaces in strings,
because in my scripts, often the strings are spreading on several lines.

For example, "aaa bbb" had to be transformed in "aaa bbb".
I have coded some simple functions to do that.

Today, by examining Python documentation, I have found an interesting
module:

http://www.python.org/doc/2.5.2/lib/...-textwrap.html

But, I haven't found any way to do my redundant space deletion with this
module? Am I right?
You may pre-process your text (stripping redundant whitespace) before
using textwrap:

pytext = 'This is some \t text with multiple\n\n spaces.'
pyprint textwrap.fill(text, width=20)
This is
some text with
multiple spaces.
pyimport re
pyre.sub(r'\s+', ' ', text)
'This is some text with multiple spaces.'
pyt2 = _
pyprint textwrap.fill(t2, width=20)
This is some text
with multiple
spaces.
py>

--
Gabriel Genellina

Oct 27 '08 #2
TP
Gabriel Genellina wrote:
You may pre-process your text (stripping redundant whitespace) before
using textwrap:
Thanks Gabriel for your answers!
I finally have subclassed textwrap.TextWrapper.

Julien
--
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
Oct 28 '08 #3
Gabriel Genellina <ga*******@yahoo.com.arwrote:
>pytext = 'This is some \t text with multiple\n\n spaces.'
pyimport re
pyre.sub(r'\s+', ' ', text)
'This is some text with multiple spaces.'
py' '.join(text.split())
'This is some text with multiple spaces.'

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Oct 29 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Kevin MacKenzie | last post: by
reply views Thread by David M. Wilson | last post: by
1 post views Thread by Joshua Burvill | last post: by
6 posts views Thread by Steven Bethard | last post: by
21 posts views Thread by Hari Sekhon | last post: by
15 posts views Thread by Tom Plunket | last post: by
reply views Thread by Jesse Aldridge | last post: by
reply views Thread by Gary Herron | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.