Is there any simple way to solve this problem? 7 49471
一首诗 wrote:
Is there any simple way to solve this problem?
>>myString = " " myString = myString.replace(" ", "")
Is this what you want?
pys = 'This string contains two times - end'
pyprint s.replace(' ', ' '*6)
This string contains two times - end
see http://docs.python.org/lib/string-methods.html
On Oct 30, 6:26 pm, "一首诗" <newpt...@gmail.comwrote:
Is there any simple way to solve this problem?
一首诗 wrote:
Is there any simple way to solve this problem?
Yes, strings have a replace method:
>>s = "abc def" s.replace(' ',' ')
'abc def'
Also various modules that are meant to deal with web and xml and such
have functions to do such operations.
Gary Herron
Oh, I didn't make myself clear.
What I mean is how to convert a piece of html to plain text bu keep as
much format as possible.
Such as convert " " to blank space and convert <brto "\r\n"
Gary Herron wrote:
一首诗 wrote:
Is there any simple way to solve this problem?
Yes, strings have a replace method:
>s = "abc def" s.replace(' ',' ')
'abc def'
Also various modules that are meant to deal with web and xml and such
have functions to do such operations.
Gary Herron
On Oct 30, 6:44 pm, "一首诗" <newpt...@gmail.comwrote:
Oh, I didn't make myself clear.
What I mean is how to convert a piece of html to plain text bu keep as
much format as possible.
Such as convert " " to blank space and convert <brto "\r\n"
Then you can explore the parser, http://docs.python.org/lib/module-HTMLParser.html, like
#!/usr/bin/env python
from HTMLParser import HTMLParser
parsedtext = ''
class Parser(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == 'br':
global parsedtext
parsedtext += '\\r\\n'
def handle_data(self, data):
global parsedtext
parsedtext += data
def handle_entityref(self, name):
if name == 'nbsp':
pass
x = Parser()
x.feed('An text<br>')
print parsedtext
Gary Herron wrote:
一首诗 wrote:
Is there any simple way to solve this problem?
Yes, strings have a replace method:
>>s = "abc def"
>>s.replace(' ',' ')
'abc def'
Also various modules that are meant to deal with web and xml and such
have functions to do such operations.
Gary Herron
一首诗 wrote:
Is there any simple way to solve this problem?
corresponds to a non-breaking space, chr(160). if you're only
dealing with this specific XML/HTML entity, you can do
text = text.replace(" ", " ")
or
text = text.replace(" ", chr(160))
to handle arbitrary entities and character references, pass the data
through an HTML or XML parser, or use something like: http://effbot.org/zone/re-sub.htm#unescape-html
</F>
一首诗 wrote:
Oh, I didn't make myself clear.
What I mean is how to convert a piece of html to plain text bu keep as
much format as possible.
Such as convert " " to blank space and convert <brto "\r\n"
Gary Herron wrote:
>一首诗 wrote:
>>Is there any simple way to solve this problem?
Yes, strings have a replace method:
>>>>s = "abc def" s.replace(' ',' ') >
'abc def'
Also various modules that are meant to deal with web and xml and such have functions to do such operations.
Gary Herron
>>my_translations = '''
" = "
# "<br>=\r\n" "<BR>=\r\n" # Windows
"<br>=\n" "<BR>=\n" # Linux
# Add others to your heart's content
'''
>>import SE # From http://cheeseshop.python.org/pypi/SE/2.2%20beta
>>My_Translator = SE.SE (my_translations)
>>print My_Translator ('ABC DEFG<br>XYZ')
ABC DEFG
XYZ
SE can also strip tags and translate all HTM escapes and generally lets
you do ad hoc translations in seconds. You just write them up, make an
SE object from your text an run your data through it. As simple as that.
If you wish further explanations, I'll be happy to explain.
Frederic This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ian justice |
last post by:
Before i post actual code, as i need a speedyish reply.
Can i first ask if anyone knows off the top of their head, if there is
a likely obvious cause to the following problem.
For the moment i've...
|
by: tertius |
last post by:
Is there a better way to append certain chars in a string with a
backslash that the example below?
chr = "#$%^&_{}" # special chars to look out for
str = "123 45^ & 00 0_" # string to...
|
by: rbronson1976 |
last post by:
Hi all,
I have a very simple page that Firefox has problems with:
www.absolutejava.com/testing.htm
First of all, this page seems to be perfectly valid XHTML Strict. Both
the W3C validator as...
|
by: Robert Mark Bram |
last post by:
Hi All,
I am using the following trim function:
function trim (str) {
return str.replace(/^\s*/g, '').replace(/\s*$/g, '');
}
The problem is that this doesn't trim instances of the...
|
by: Naveen K Kohli |
last post by:
I am try to set the text of the drop down list item as
ListItem li = new ListItem();
li.Text = " "+"MyValue";
myDropDown.Items.Add("li);
The intent is to add a spacing in front of the...
|
by: ratnakarp |
last post by:
Hi,
I have a search text box. The user enters the value in the text box and
click on enter button. In code behind on button click i'm writing the
code to get the values from the database and...
|
by: K B |
last post by:
Hi again,
I have a gridview, when I get the selecteditem.cells for a column, if
the database column is Null or Empty, and I assign that to my web form
text control, the control reads " "...
|
by: John Nagle |
last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally
hit content which has something like "Design & Advertising", that is,
an "&" instead of an "&". Is there some way I can get...
|
by: Just Another Victim of the Ambient Morality |
last post by:
I've done a google search on this but, amazingly, I'm the first guy to
ever need this! Everyone else seems to need the reverse of this. Actually,
I did find some people who complained about this...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |