Building proper link with spaces

Posted by Joel on Stack Overflow See other posts from Stack Overflow or by Joel
Published on 2010-04-24T07:44:20Z Indexed on 2010/04/24 7:53 UTC
Read the original article Hit count: 214

Filed under:

Hello,

I have the following code in Python:

linkHTML = "<a href=\"page?q=%s\">click here</a>" % strLink

The problem is that when strLink has spaces in it the link shows up as

<a href="page?q=with space">click here</a>

I can use strLink.replace(" ","+")

But I am sure there are other characters which can cause errors. I tried using

urllib.quote(strLink)

But it doesn't seem to help.

Thanks! Joel

© Stack Overflow or respective owner

Related posts about python