newbie string.replace question

William Park opengeometry at yahoo.ca
Wed Aug 8 17:16:46 EDT 2001


On Wed, Aug 08, 2001 at 05:07:39PM -0400, fett at tradersdata.com wrote:
> Could someone please tell me why the following segment of code wont
> work:
> 
> unformat = quote[11]
> string.replace(unformat, '<B>', '')   
> string.replace(unformat, '</DL>', '')  
> string.replace(unformat, '</B>', '')
> string.replace(unformat, '<DL COMPACT>', '')
> string.replace(unformat, '<DT>', '')
> string.replace(unformat, '<DD>', '')
> string.replace(unformat, '<OL>', '')
> string.replace(unformat, '</OL>', '')
> 
> when i print the html stuff i was replacing is still there.

string.replace() returns the result and leaves the original untouched.
So, what you want is
    unformat = quote[11]
    unformat = string.replace(unformat, '<B>', '')   
    ...
or
    unformat = quote[11]
    for i in ('<B>', ...):
	unformat = string.replace(unformat, i, '')   
    
-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
8 CPUs cluster, (Slackware) Linux, Python, LaTeX, Vim, Mutt, Sc.




More information about the Python-list mailing list