Python: why is __dict__ attribute not in built-in class instances
Just to add to this:
You can get the equivalent of a read only __dict__
using this:
{s:getattr(x, s) for s in dir(x)}
EDIT: Please note that this may contain more entries than __dict__
. To avert this, you may use this as a workaround:
{s:getattr(x, s) for s in dir(x) if not s.startswith("__")}
Instances of types defined in C don't have a __dict__ attribute by default.