quick unicode Q

J

John Morey

I have a variable that contains a string which may or may not include
unicode characters, I understand that I declare a unicode string like this
u'whatever' , the question is that when that string is read in from
an external source (in this case an id3 tag) how do I make the
interpretter understand that it may contain unicode?

cheers
 
E

Erik Max Francis

John said:
I have a variable that contains a string which may or may not include
unicode characters, I understand that I declare a unicode string like this
u'whatever' , the question is that when that string is read in from
an external source (in this case an id3 tag) how do I make the
interpretter understand that it may contain unicode?

Read it as a string, and then decode it with the .decode method. You
specify what encoding it's in.
 
H

Heiko Wundram

Erik said:
Read it as a string, and then decode it with the .decode method. You
specify what encoding it's in.

Most probably, the OP is asking what to do with an UTF-8 encoded string.

To decode that, just use:

s.decode("utf-8")

to get a unicode string object.

Example:

HTH!

--- Heiko.
 
D

Damjan

Read it as a string, and then decode it with the .decode method. You
Most probably, the OP is asking what to do with an UTF-8 encoded string.

To decode that, just use:

s.decode("utf-8")

I prefer:

unicode(s, 'utf-8')

That way it's more clear that what you get is a unicode object.
 

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

Staff online

Members online

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,054
Latest member
Ruby74713

Latest Threads

Top