eln00by
eln00by

Reputation: 13

python unicode support

I'm trying to figure out how to use the unicode support in python; I would like to convert this string to unicode : "ABCDE" --> "\x00A\x00B\x00C\x00D\x00E"

Any built-in functionnality can do that, or shall i use join() ?

Thanks !

Upvotes: 1

Views: 781

Answers (3)

Eric
Eric

Reputation: 464

the str object should be firstly converted to unicode object by decode method. then convert the unicode object to str object using encode method with character-encoding you want.

Upvotes: 0

Tyler Eaves
Tyler Eaves

Reputation: 13121

The key to understanding unicode in python is that unicode means UNICODE. A unicode object is an idealized representation to the characters, not actual bytes.

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798456

That's UTF-16BE, not Unicode.

>>> 'ABCDE'.decode('ascii').encode('utf-16be')
'\x00A\x00B\x00C\x00D\x00E'

Upvotes: 5

Related Questions