[Python-3000] Bytes to Unicode Conversion

Nick Coghlan ncoghlan at gmail.com
Sun Nov 16 21:34:01 CET 2008


Pb2Au wrote:
> On Sun, Nov 16, 2008 at 4:31 PM, Chris Rebert <cvrebert at gmail.com>: wrote:
>>
>>Already exists. Has for quite a while now:
>>
>>the_unicode = unicode(some_bytes, "name of encoding")
>
> I know that it had worked in the version 2.5, Python 3.0 rc2 doesn't
> seem to recognize it as a function.
> 
> Python 3.0rc2 (r30rc2:67141, Nov  7 2008, 11:43:46) [MSC v.1500 32 bit
> (Intel)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> unicode()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'unicode' is not defined

unicode becomes str in Py3k (as "type('')" will tell you).

bytes.decode() works as well.

Use str.encode() to go the other way.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------


More information about the Python-3000 mailing list