Where is the ucs-32 codec?

Fredrik Lundh fredrik at pythonware.com
Fri Jun 9 09:48:59 EDT 2006


cben at users.sf.net wrote:

> Somebody asked me about generating UTF-32 (he didn't have choice of the
> output format).  I was about to propose the obvious ``u.encode('utf-32')``
 > but discovered it's missing.

hint 1:

 >>> u = u"Hello"
 >>> a = array.array("I", map(ord, u))
 >>> a.tostring()
'H\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00'
 >>> a.byteswap()
 >>> a.tostring()
'\x00\x00\x00H\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o'

hint 2:

 >>> import sys
 >>> sys.byteorder
'little'

</F>




More information about the Python-list mailing list