change string to unicode

Peter Otten __peter__ at web.de
Fri Dec 19 10:55:20 EST 2008


jyoung79 at kc.rr.com wrote:

> If I have a string like so:
> 
> a = '\\u03B1'
> 
> and I want to make it display a Greek alpha character, is there a way to
> convert it to unicode ('\u03B1')?  I tried concatenating it like this:
> 
> '\u' + '03B1'
> 
> but that didn't work.  I'm working in Python 3.0 and was curious if this
> could be done.

How about

>>> "\\u03b1".encode("ascii").decode("unicode-escape")
'α'

Peter



More information about the Python-list mailing list