Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does dir of a module show no __dict__? (python)

For example:

>>> import os
>>> '__dict__' in dir(os)
False

But os.__dict__ shows there is a __dict__ attribute.

like image 321
Ella Sharakanski Avatar asked Nov 30 '13 14:11

Ella Sharakanski


1 Answers

Because dir uses a specialized implementation for modules, which returns all the keys in the module's __dict__, and thus neglects to include the __dict__ attribute itself.

It is not clear from reading the source code whether this is intentional.

like image 159
user4815162342 Avatar answered Sep 22 '22 16:09

user4815162342