__cached__ — Intermediate Examples
Path to the compiled bytecode (.pyc) file of the module
__cached__ with custom classes
Working with __cached__ in your own classes.
python
# Using __cached__ with custom classes class Registry: def __init__(self): self._items = {} def register(self, cls): self._items[cls.__name__] = cls return cls def get(self, name): return self._items.get(name) registry = Registry() @registry.register class Widget: pass @registry.register class Button: pass print(registry._items) print(registry.get("Widget"))
Custom classes interact with __cached__ in specific ways that are useful to understand.
Want to try these examples interactively?
Open Intermediate Playground