Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hash() returning different values on different OSs

When python builtin hash() is just wired cross-platform. I have an app use builtin hash() for 'test'. Both systems are 64bit, python 2.7.12

windows:

>>> hash('test')
1308370872

linux:

>>> hash('test')
2314058222102390712

Why is this?

like image 966
wiwengweng Avatar asked Oct 27 '25 10:10

wiwengweng


1 Answers

There are no guarantees about the value hash returns in Python. It appears that you're using a 32-bit Windows Python (that's a guess), and that you're using a 64-bit python on linux (again, a guess). IIRC (and I haven't checked), The default hash(item) returns the address of item as its hash value.

If you want to have values you can compare across operating systems, look at hashlib.

like image 78
cco Avatar answered Oct 29 '25 00:10

cco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!