0

Hey guys I am trying to convert this in python 2.7.3:

the+c\xf8\xf8n

to the html string:

the+c%C3%B8%C3%B8n

It was original the c\xf8\xf8n but I did use a replace to use a + instead of the space.

I'm not entirely sure what convention the latter is I would use string replace but the convention changes by the different characters..

Thoughts? Thanks guys

1 Answer 1

1

You are URL encoding, not HTML. Use urllib.quote:

from urllib import quote

but make sure you encode to UTF-8 first:

quote(inputstring.encode('utf8'))

This will quote the + explicitly; if you meant that to be a space character, you need to mark that as safe:

quote(inputstring.encode('utf8'), '+')

The latter form gives:

>>> quote(inputstring.encode('utf8'), '+')
'the+c%C3%B8%C3%B8n'
Sign up to request clarification or add additional context in comments.

1 Comment

Doh! I totally spaced on the URL encoding I will try this out and post, Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.