hash() 在不同的操作系统上返回不同的值
hash() returning different values on different OSs
当 python 内置 hash()
只是有线跨平台。我有一个应用程序使用内置 hash()
for 'test'
。两个系统都是64位的,python 2.7.12
windows:
>>> hash('test')
1308370872
linux:
>>> hash('test')
2314058222102390712
这是为什么?
Python 中的值 hash
returns 没有任何保证。看来您正在使用 32 位 Windows Python(这是一个猜测),并且您在 linux 上使用 64 位 python(再次, 一个猜想)。 IIRC(我没查过),默认hash(item)
returns地址item
作为它的hash值。
如果您想获得可以跨操作系统比较的值,请查看 hashlib。
当 python 内置 hash()
只是有线跨平台。我有一个应用程序使用内置 hash()
for 'test'
。两个系统都是64位的,python 2.7.12
windows:
>>> hash('test')
1308370872
linux:
>>> hash('test')
2314058222102390712
这是为什么?
Python 中的值 hash
returns 没有任何保证。看来您正在使用 32 位 Windows Python(这是一个猜测),并且您在 linux 上使用 64 位 python(再次, 一个猜想)。 IIRC(我没查过),默认hash(item)
returns地址item
作为它的hash值。
如果您想获得可以跨操作系统比较的值,请查看 hashlib。