replace characters not working in python

replace characters not working in python

string.replace() returns the string with the replaced values. It doesnt modify the original so do something like this:

link[href] = link[href].replace(.., )

string.replace() returns a copy of the string with characters replaced, as strings in Python are immutable. Try

s = link[href].replace(.., )
url=urljoin(page, s)

replace characters not working in python

It is not an inplace replacement. You need to do:

link[href] = link[href].replace(.., )

Example:

a = abc..
print a.replace(..,)
abc
 print a
abc..
a = a.replace(..,)
print a
abc

Leave a Reply

Your email address will not be published. Required fields are marked *