__dict__ attribute for built-in types

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Oct 27 18:19:18 EDT 2011


On Thu, 27 Oct 2011 16:01:25 +0200, candide wrote:

> OK, thanks for the information abouts the slots. Nevertheless, this
> cannot answer completely my question. Some builtin types like string,
> lists, integer, float, dictionaries, etc have the property that
> instances of those types don't provide a __dict__ attribute. I can't
> imagine the documentation lets pass silently this point.

What, you think it goes against the laws of physics that nobody thought 
to mention it in the docs? <wink>

> But beside this, how to recognise classes whose object doesn't have a
> __dict__ attribute ?

The same way as you would test for any other attribute.

>>> hasattr(42, '__dict__')
False


-- 
Steven



More information about the Python-list mailing list