hashability

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Wed Aug 12 14:11:40 EDT 2009


On Wed, 12 Aug 2009 10:37:45 -0700, James Stroud wrote:

> Steven D'Aprano wrote:
>> Well there you go -- why on earth would you prohibit None as a
>> dictionary key??? That's a serious failure.
> 
> 
> roentgen 1% python
> Python 2.5 (r25:51908, Sep 20 2006, 17:36:21) [GCC 3.4.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> py> hash(None)
> 135543872
> 
> 
> mbi136-176 98% /usr/bin/python
> Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc.
> build 5465)] on darwin Type "help", "copyright", "credits" or "license"
> for more information. py> hash(None)
> 2030240
> 
> 
> 
> That's why. Read the whole thread. You are one of the abrasive ones.

I've read the whole thread. Pay close attention:

[steve at ando ~]$ python
Python 2.4.3 (#1, Mar 14 2007, 18:51:08)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> d = {None: 42}
>>> f = open('pickled_dict', 'w')
>>> pickle.dump(d, f)
>>> f.close()
>>>
[steve at ando ~]$ ssh sylar
steve at sylar's password:
Last login: Wed Aug 12 21:44:47 2009
[steve at sylar ~]$ python2.6
Python 2.6.1 (r261:67515, Dec 24 2008, 00:33:13)
[GCC 4.1.2 20070502 (Red Hat 4.1.2-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> f = open('pickled_dict', 'r')
>>> d = pickle.load(f)
>>> d
{None: 42}


I have successfully pickled a dict using None as a key on one machine 
using Python 2.4, and unpickled it on a completely different machine 
running Python 2.6.

Still think that pickling None is a problem?



-- 
Steven



More information about the Python-list mailing list