__dict__ attribute for built-in types

Amirouche Boubekki amirouche.boubekki at gmail.com
Thu Oct 27 11:49:20 EDT 2011


2011/10/27 candide <candide at free.invalid>

> I realize that built-in types objects don't provide a __dict__ attribute
> and thereby i can't set an attribute to a such object, for instance
>
>
> >>> a=[42,421]
> >>> a.foo="bar"
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> AttributeError: 'list' object has no attribute 'foo'
> >>> a.__dict__
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> AttributeError: 'list' object has no attribute '__dict__'
> >>>
>
>
> So, i was wondering :
>
> -- why this behaviour ?
>

performance


> -- where the official documentation refers to this point ?
>

it's here and there in python documentation. I did not find specific
documentation about the __dict__ property.

Have a look at :

- naming conventions in http://www.python.org/dev/peps/pep-0008/
- http://docs.python.org/library/stdtypes.html#modules

__dict__ is similar to other __*__ properties and has a function that
actually use it to do something usefull aka. dir
http://docs.python.org/library/functions.html#dir

The way I understand it is that it's for internal use but it's exposed for
debugging (and learning ?) purpose.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111027/daaf8429/attachment-0001.html>


More information about the Python-list mailing list