convert gb18030 to utf16

Discussion in 'Python' started by Xah Lee, Mar 6, 2005.

  1. Xah Lee

    Xah Lee Guest

    Xah Lee, Mar 6, 2005
    #1
    1. Advertising

  2. Xah Lee

    Guest

    Xah Lee <> 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:
    http://www.doxdesk.com/
     
    , Mar 6, 2005
    #2
    1. Advertising

  3. Xah Lee

    Xah Lee Guest

    Truely superb!

    Thanks!

    Xah

    http://xahlee.org/



    wrote:
    > Xah Lee <> 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:
    > http://www.doxdesk.com/
     
    Xah Lee, Mar 7, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Perks and Sarah Mount

    UTF16 codec doesn't round-trip?

    John Perks and Sarah Mount, May 28, 2005, in forum: Python
    Replies:
    1
    Views:
    451
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    May 28, 2005
  2. Fuzzyman
    Replies:
    4
    Views:
    565
    Fuzzyman
    Feb 7, 2006
  3. news.fe.internet.bosch.com

    Regarding UTF16

    news.fe.internet.bosch.com, Feb 2, 2006, in forum: C Programming
    Replies:
    5
    Views:
    356
    those who know me have no need of my name
    Feb 12, 2006
  4. Cal
    Replies:
    0
    Views:
    855
  5. Xah Lee

    convert gb18030 to utf16

    Xah Lee, Mar 7, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    118
    Xah Lee
    Mar 7, 2005
Loading...

Share This Page