On this page
  1. collections.UserDict
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

collections.UserDict

Prev: collections.OrderedDict | Up: collections | Next: collections.UserList
Rel: collections.ChainMap, collections.Counter, collections.defaultdict, collections.deque
Ref: docs.python.org — collections.UserDict
Tags: #public #python3 #stdlib #collections


Import

import collections
from collections import UserDict

Signature & Overview

collections.UserDict(dict=None, /, **kwargs)

collections.UserDict class.

Methods & Attributes

Usage

from collections import UserDict

class LowerKeyDict(UserDict):
    def __setitem__(self, key: str, value) -> None:
        super().__setitem__(key.lower(), value)

d = LowerKeyDict({"Host": "localhost"})
assert d["host"] == "localhost"

Gotchas

REPL Inspect

from collections import UserDict
help(UserDict)

Linked from

Related notes