change string to unicode

G

Guest

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.

Thanks.

Jay
 
S

Steven D'Aprano

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.

This is from Python 2.5:
α

I don't have Python 3 here, but I guess that you would just use chr()
instead of unichr().

If you literally have to start with the actual string '\\u03B1' (that is,
backslash lowercase-U zero three uppercase-B one), then I'd do this:
.... s = s[2:]
....α
 
P

Peter Otten

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
'α'

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top