Help with hashcode (ARG!!!)

Bob asw204k at
Sat Aug 24 00:07:35 CEST 2002

Me again,

I'm trying to sync python hash with the java.lang.String.hashCode().
based on a few suggestions, I'm trying Jython. But can't seem to 
access the python hash method. Here are the code snips.

public String convert(String str ) 
    PythonInterpreter interp = new PythonInterpreter();
    interp.set("hc", new PyString());
    interp.exec("hc = str(hash(\""+ str +"\"))");
    PyObject x = interp.get("hc");
    return "" + x;

foo.convert("DOG") returns 67868

import sys
s = sys.argv[1]
print str(hash( s ))

python DOG returns -595261171

What's up ????? Does anyone know how to match hashcodes ????? Is there a bug
in Jython ????

Thanks- Bob

More information about the Python-list mailing list