Chris Rebert chris at rebertia.com
Wed Aug 12 07:52:51 CEST 2009

2009/8/11 Asun Friere <afriere at yahoo.co.uk>:
> On Aug 12, 12:15 pm, James Stroud <jstr... at mbi.ucla.edu> wrote:
>> I realize I left out my use. The intent of the function is to flag
>> objects that will make useful keys for a persistent dictionary. The
>> {C():4}[C()] example demonstrates why I want to avoid certain types of
>> keys--I don't want users to do things like {C():4, C():4}, which python
>> happily allows but falls apart at the level of persistence.
> What am I missing here?  How, in terms of persistence, is {C():4, C():
> 4} conceptually different from {'spam':4, 'ham':4}?

Thought Experiment:
Consider, for each dict, the case of pickling it twice to 2 separate files.
When loaded from both files into the same program, the spam-ham dicts
will work as expected between each other.
The dicts with C()s will not. For example, assuming the unpickled
dicts are `cs1` and `cs2`, cs1[cs2.keys()[0]] will raise KeyError.


More information about the Python-list mailing list