replace characters not working in python [duplicate]
Solution 1:
string.replace() returns the string with the replaced values. It doesn't modify the original so do something like this:
link['href'] = link['href'].replace("..", "")
Solution 2:
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)
Solution 3:
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'