Problems with encoding/decoding locales

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michele

    Problems with encoding/decoding locales

    Hi there,
    I'm using a python script in conjunction with a JPype, to run java classes.
    So, here's the code:

    from jpype import *
    import os
    import random
    import math
    import sys

    input = open('foo.img', 'rb').read().de code('ISO-8859-1')

    square = java.encoding(i nput)

    output = java.decoding()

    fd = open('foo_decod e.img','wb')
    fd.write(output .encode('ISO-8859-1'))
    fd.close()
    sys.exit(0)

    First of all, java.encoding and java.decoding are two methods that
    respectively take a java string as an argument and return a java String.
    JPype is the bridge between Java and Python, and converts automatically
    a str or unicode pythonstring into a Java String.
    So, input and output are two unicode strings. I were forced to use
    decode() and encode() methods by python, otherwise it refuses to read
    foo.img file.
    Here's the strange behaviour: when I write the output in the
    'foo_decode.img ', I don't reassemble the original file; I already tested
    the java encoding/decoding libraries with the same input file, and what
    the decoding process returns is the original file.
    I suspect that the discrepancy is due to encoding/decoding of
    ISO-8859-1: is that required?
    What do you think about?

    Thank you





Working...