Maybe that’s what you’re looking for:
plaintext = u'algor\u00edtimo'
encodedtext = plaintext.encode('utf-8')
print (encodedtext)
DEMO
To encode a string for ascii can do:
plaintext = u'algor\u00edtimo'
decodedtext = plaintext.encode('ascii', 'ignore').decode('ascii')
print (decodedtext) # algortimo
The second function parameter encode
causes likely errors to be ignored in conversion.
To decode a string you can use the function decode
(or unicode
):
plaintext = u'algor\u00edtimo'
encodedtext = plaintext.encode('utf-8')
decodedtext = encodedtext.decode('utf-8')
print (encodedtext) # algorítimo
print repr(decodedtext) # u'algor\xedtimo'
DEMO
This is applicable to Python 2, for 3 there are some differences, for more information see Unicode HOWTO. See also the coding standards.
If it is possible to specify better in which part you are having difficulties gets better to solve the problem.
Well, off-topic, but respondendp..."algorithm" has no accent...is with "t" muted, so it’s not proparoxitone.
– jsbueno
Thanks for commenting jsbueno.. plus this was just an example of a Rawler I’m doing to fetch post titles from a forum. Hug
– LeoCBS