Hi list,
Can I make TextWrapper keep line breaks in the text?
For example,
>>s = "spam\nham" print wrap(s)
spam
ham
As far as I can tell, there seems no way to do this,
but before writing my own solution, I want to know whether
the solution already exists or not.
Thanks. 2 2121
On Mar 10, 11:31*pm, js <ebgs...@gmail.comwrote:
Hi list,
Can I make TextWrapper keep line breaks in the text?
For example,
>s = "spam\nham" print wrap(s)
spam
ham
As far as I can tell, there seems no way to do this,
but before writing my own solution, I want to know whether
the solution already exists or not.
Thanks.
Don't know but you could write:
>>import textwrap def wraplines(text):
... return '\n'.join(textwrap.fill(line) for line in
text.split('\n'))
...
>>s = "spam\nham" print wraplines(s)
spam
ham
>>>
HTH
--
Arnaud
Hi Arnaud,
Great. Thanks for your help!
On Tue, Mar 11, 2008 at 10:27 AM, Arnaud Delobelle
<ar*****@googlemail.comwrote:
>
On Mar 10, 11:31 pm, js <ebgs...@gmail.comwrote:
Hi list,
>
Can I make TextWrapper keep line breaks in the text?
>
For example,
>
>s = "spam\nham"
>print wrap(s)
>
spam
ham
>
As far as I can tell, there seems no way to do this,
but before writing my own solution, I want to know whether
the solution already exists or not.
>
Thanks.
Don't know but you could write:
>>import textwrap
>>def wraplines(text):
... return '\n'.join(textwrap.fill(line) for line in
text.split('\n'))
...
>>s = "spam\nham"
>>print wraplines(s)
spam
ham
>>>
HTH
--
Arnaud
-- http://mail.python.org/mailman/listinfo/python-list This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dan glenn |
last post by:
Hi. I'm finding that if I have text entered into a
<textarea ...> </textarea> in a form, and that text
has leading blank lines (with no spaces or anything
else), that when I retrieve the entered...
|
by: Bill |
last post by:
I am downloading data from a website that displays it in a table
$fp = fopen("a website page", 'r');
The following accesses the stream one <td> element at a time
$myData = fgets($fp);
Then I...
|
by: Jonathan |
last post by:
I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags
in HTML. How can I do that. So far, although it occurs naturally...
|
by: scott |
last post by:
Is there a way to prevent IE from forcing a line break? Below in LISTING 2,
you notice the table background image extention of '.jpg' begins a new line,
instead of staying on the same line as it's...
|
by: intl04 |
last post by:
I have a memo field that is included in some Access reports I created.
Is there some way for the memo field to display nicely formatted text,
with line breaks between paragraphs? Or is it necessary...
|
by: Mike |
last post by:
I need my textbox to work more smoothly with respect to line breaks.
When I have data pulled from the database into a textbox there are hard
line breaks at the end of each line (by definition how...
|
by: joelbyrd |
last post by:
Didn't know exactly where to post this, but: How do I get line breaks
in a textarea? I'm pulling text from a database, and this text
definately has line breaks in it, because I
replaced all the...
|
by: caspardh |
last post by:
i was trying to code a morse code decipherer which workd fine except that the .txt file that i was converting had linebreaks built in, i cant get python to ignore the line breaks and i cant find any...
|
by: =?ISO-8859-1?Q?thib=B4?= |
last post by:
Hi,
Taking a closer look to highlight_file() lastly, I found out that its line
break policy was a bit.. strange.
<?php # highlight_file() line breaks test
$f = fopen('highlight_file_test',...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |