I would like to convert this string
foo_utf = u'nästy chäräctörs with å and co.' # unicode
into this
foo_ascii = 'nästy chäräctörs with å and co.' # ASCII
.
Any idea how to do this in Python (2.6)? I found unicodedata module but I have no idea how to do the transformation.
I don't think you can. Those "nästy chäräctörs" can't be encoded as ASCII, so you'll have to pick a different encoding (UTF-8 or Latin-1 or Windows-1252 or something).
This really is a Django question, and not a python one.
if the string is in one of your .py files, make sure that you have the following line on top of your file:
-*- coding: utf-8 -*-
furthermore, your string needs to be of type "unicode" (u'foobar')
And then make sure that your html page works in unicode:
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
That should do the whole trick. No encoding/decoding etc. necessary, just make sure that everything is unicode, and you are on the safe side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With