Help with hashcode (ARG!!!)

Gerhard Häring gerhard.haering at gmx.de
Fri Aug 23 19:17:02 EDT 2002


Bob wrote in comp.lang.python:
> 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.
> 
> JAVA:
> [snip Jython example]
> 
> foo.convert("DOG") returns 67868
> 
> PYTHON:
> python foo.py DOG returns -595261171

CPython, right?

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

Hash codes are implementation defined. Why do you need them to be
equal in Jython and CPython? If you _really_ need the same hash codes,
I'd recommend to use crc32, md5, sha, whatever _specified_ (string)
hashing algorithm instead.
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))



More information about the Python-list mailing list