唉,数据模型文档是我能想到的最完整的东西,它甚至没有真正设计为索引。不过,我并不完全清楚你在寻找什么;__all__
是一个全局模块,__slots__
是一个类属性,__weakref__
仅以字符串形式出现在槽列表中,并且__module__
是一个函数属性等。我猜想有什么特殊属性通常不可调用吗?
当然,你可以随时询问Python。
>>> dir(type)
['__abstractmethods__', '__base__', '__bases__', '__basicsize__', '__call__', '__class__', '__delattr__', '__dict__', '__dictoffset__', '__dir__', '__doc__', '__eq__', '__flags__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__instancecheck__', '__itemsize__', '__le__', '__lt__', '__module__', '__mro__', '__name__', '__ne__', '__new__', '__prepare__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasscheck__', '__subclasses__', '__subclasshook__', '__weakrefoffset__', 'mro']
>>> import sys
>>> dir(type(sys))
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
一眼望去你肯定缺了__mro__
and __subclasses__
。让事情变得更加复杂的是,有一些特殊方法仅由恰好内置于 Python 中的代码使用,而不是由核心语言使用:示例包括__format__
(由str.format
)和各种 ABC 方法。
我什至不知道什么__weakrefoffset__
is.
请注意,Python 3 有一些新东西:__prepare__
元类恶作剧使用的方法、函数和方法现在使用魔法名称作为其属性,而不是像噪音一样im_self
(请参阅数据模型的“用户定义函数”部分),并且有一个__qualname__
在模块和类上。
另外,导入PEP http://www.python.org/dev/peps/pep-0302/#specification-part-1-the-importer-protocol准确地提到了模块加载器应该做什么,包括设置一些神奇的属性:__name__
, __file__
, __path__
, __loader__
, and __package__
.