__cached__ — Easy Examples
Path to the compiled bytecode (.pyc) file of the module
Accessing __cached__
How to access and use __cached__.
python
# __cached__ print("Demonstrating __cached__") print(type(object).__dict__.keys())
__cached__ is a special attribute that path to the compiled bytecode (.pyc) file of the module.
__cached__ in practice
Using __cached__ in everyday code.
python
# More __cached__ examples print("__cached__ is a special Python attribute") # Every object has certain dunder attributes obj = object() attrs = [a for a in dir(obj) if a.startswith("__")] print(f"object has {len(attrs)} dunder attributes")
Understanding __cached__ helps you introspect and debug Python objects.
Want to try these examples interactively?
Open Easy Playground