Re: Convert unicode escape sequences to unicode in a file

Discussion in 'Python' started by Jeremy, Jan 11, 2011.

  1. Jeremy

    Jeremy Guest

    On Tuesday, January 11, 2011 3:36:26 PM UTC-7, Alex wrote:

    >
    > Are you _sure_ that your file contains the characters '\', 'u', '0',
    > '0', 'e' and '9'? I expect that actually your file contains a byte
    > with value 0xe9 and you have inspected the file using Python, which
    > has printed the byte using a Unicode escape sequence. Open the file
    > using a text editor or hex editor and look at the value at offset 947
    > to be sure.
    >
    > If so, you need to replace 'unicode-escape' with the actual encoding
    > of the file.


    Yeah, I'm sure that's what the file contains. In fact, I solved my own problem while waiting for an answer. When writing to the file I need to *en*code instead of *de*code; i.e.,

    o = open('newDice.sql', 'w')
    o.write(utFound.encode('utf-8'))
    o.close()

    That works!
    Jeremy, Jan 11, 2011
    #1
    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. harrelson
    Replies:
    3
    Views:
    3,901
    Craig Ringer
    Dec 10, 2004
  2. slomo
    Replies:
    5
    Views:
    1,535
    Duncan Booth
    Dec 2, 2007
  3. Guest
    Replies:
    2
    Views:
    563
    Tim Roberts
    Dec 15, 2007
  4. Guest
    Replies:
    4
    Views:
    710
    Martin v. Löwis
    Dec 19, 2007
  5. Jeremy
    Replies:
    1
    Views:
    805
    Alex Willmer
    Jan 11, 2011
Loading...

Share This Page