[Python] How to create an immutable dictionary in python?

Discussão em 'Python' iniciado por Stack, Junho 4, 2025.

  1. Stack

    Stack Membro Participativo

    I want to subclass dict in python such that all the dictionaries of the sub-class are immutable.

    I don't understand how does __hash__ affects the immutability, since in my understanding it just signifies the equality or non-equality of objects !

    So, can __hash__ be used to implement immutability ? How ?

    Update:

    Objective is that common response from an API is available as a dict, which has to be shared as a global variable. So, that needs to be intact no matter what ?

    Continue reading...

Compartilhe esta Página