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().decode('ISO-8859-1')

square = java.encoding(input)

output = java.decoding()

fd = open('foo_decode.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





.



Relevant Pages

  • Python + Java Integration
    ... One of the reasons for Ruby's success is certainly the notion that it is the "next Java" -- the language and environment that mainstream Java developers are, or will, look to as a natural next step. ... One thing that would help Python in this "debate" would be if Python had an easier migration path for Java developers that currently rely upon various third-party libraries. ... JPype is a module that gives "python programs full access to java class libraries". ...
    (comp.lang.python)
  • Re: Java -> ActionScript?
    ... Lage sein Java zu verdrängen? ... In Ruby geht das ja, ... Andere Sprachen wie Python oder auch Ruby sind eh ... Die Syntax sollte jedoch das Programm nicht begraben. ...
    (de.comp.lang.java)
  • Re: Integration with java (Jpype vs. JPE)
    ... core in Java and do some scripting with Jython, ... using Python also ... as a glue layer, write independent code in Java ... wrappers around Java packages written using JPype. ...
    (comp.lang.python)
  • Re: Python or Java or maybe PHP?
    ... Python or Java? ... Ruby (with Rails, of course, as the server-side framework), Python (many ... this cuts both ways (once you've decided on Java as the language you ...
    (comp.lang.python)
  • Re: iniziare a programmare
    ... studiare python o ruby (anche se ora vorrei leggere qualcosa su python, ... javascript(ma quest ultimi non sono utili al fine del post) ... Ruby si accorge immediatamente di cosa intendo quando voglio dire che ... Java è macchinoso. ...
    (it.comp.macintosh)