Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, everybody noticed the extremely obvious workaround (that took my some days to come up with), just put an attribute on <code>File</code> that tells you which folder it is in. (Don't worry, that is also what I did.)</p> <p>But, it turns out that I was working under wrong assumptions. You are not supposed to use mutable objects as keys, but that doesn't mean you can't (diabolic laughter)! The default implementation of <code>__hash__</code> returns a unique value, probably derived from the object's address, that remains constant in time. And the default <code>__eq__</code> follows the same notion of object identity.</p> <p>So you can put mutable objects in a dict, and they work as expected (if you expect equality based on instance, not on value).</p> <p>See also: <a href="https://stackoverflow.com/questions/4418741/im-able-to-use-a-mutable-object-as-a-dictionary-key-in-python-is-this-not-disa">I&#39;m able to use a mutable object as a dictionary key in python. Is this not disallowed?</a></p> <p>I was having problems because I was pickling/unpickling the objects, which of course changed the hashes. One could generate a unique ID in the constructor, and use that for equality and deriving a hash to overcome this.</p> <p>(For the curious, as to why such a "lookup based on instance identity" dict might be neccessary: I've been experimenting with a kind of <a href="https://stackoverflow.com/questions/5126776/query-language-for-python-objects">"object database"</a>. You have pure python objects, put them in lists/containers, and can define indexes on attributes for faster lookup, complex queries and so on. For foreign keys (1:n relationships) I can just use containers, but for the backlink I have to come up with something clever if I don't want to modify the objects on the <em>n</em> side.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload