convert gb18030 to utf16

Xah Lee xah at xahlee.org
Mon Mar 7 08:35:25 EST 2005


Truely superb!

Thanks!

 Xah
 xah at xahlee.org
 http://xahlee.org/



and-google at doxdesk.com wrote:
> Xah Lee <xah at xahlee.org> wrotE:
>
> > i have a bunch of files encoded in GB18030. Is there a way to
convert
> > them to utf16 with python?
>
> You will need CJKCodecs (http://cjkpython.i18n.org/), or Python 2.4,
> which has them built in. Then just use them like any other codec. eg.
>
>   f= open(path, 'rb')
>   content= unicode(f.read(), 'gb18030')
>   f.close()
>   f= open(path, 'wb')
>   f.write(content.encode('utf-16'))
>   f.close()
>
> --
> Andrew Clover
> mailto:and at doxdesk.com
> http://www.doxdesk.com/




More information about the Python-list mailing list