Pre-PEP: __hashable__

Chad Netzer cnetzer at mail.arc.nasa.gov
Wed Dec 11 14:49:36 EST 2002


On Tuesday 10 December 2002 20:45, Lulu of the Lotus-Eaters wrote:
> Chad Netzer <cnetzer at mail.arc.nasa.gov> wrote:
> |>  key = tuple(dct.items())
> |
> |Not all tuples are hashable.
>
> True enough.  I was trying to give you what you asked for, but no
> more (i.e. an immutable version of a dictionary).

Okay.  But since you labelled the result as 'key', I wanted to 
emphasize that you can't reliably use what you constructed as a 
key.

> Of course, if you want something *hashable*, you could try:
>
>     key = cPickle.dumps(dct)
>
> or,
>
>     key = pprint.pformat(dct)

Indeed, I've considered using the first on rare occasions (and then 
always reconsidered and did something more sane. :) ).  In my test 
cases for my code I always try to pickle my classes (and 
functions), just because if they don't pickle properly, I know I'm 
probably doing something very unneccessary (and if I later decide I 
actually need to pickle it, it already works).

  I won't even dignify the second one. :)

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list