查找所有双下划线变量的列表
在哪里可以找到 Python 中常用的所有双下划线变量的列表?
在Python中,以双下划线开头和结尾的变量通常用于存储元数据或内置到系统中。例如,
#!/usr/bin/env python
__author__ = 'Michael0x2a'
__license__ = 'GPL'
class Test(object):
def __init__(self):
print 'Hello World!'
if __name__ == '__main__':
t = Test()
我非常确定 __author__
和 __license__
是众所周知的。还有哪些其他双下划线元数据变量?我可以在某处查看完整的列表吗?我可以自己编造吗?还是有一堆已经成为我应该使用的事实上的标准?
像 __init__
、__name__
和 __doc__
之类的东西几乎都内置在 Python 中。这些是唯一保留的双下划线变量吗?还有吗?有什么地方可以拿到清单吗?
相关:
- Python文件的常见标头格式是什么?
- 我需要 __closure__ (链接到 这张思维导图由一堆双下划线变量组成)
Where can I find a list of all double-underscore variables that are commonly used in Python?
In Python, variables starting and ending with double underscores are typically to store metadata or are built into the system. For example,
#!/usr/bin/env python
__author__ = 'Michael0x2a'
__license__ = 'GPL'
class Test(object):
def __init__(self):
print 'Hello World!'
if __name__ == '__main__':
t = Test()
I'm pretty certain __author__
and __license__
are pretty well known. What other double-underscore metadata variables are there? Is there a comprehensive list I can check somewhere? Can I just make up my own, or are there a bunch of ones that have become de-facto standards that I should use?
Things like __init__
, __name__
, and __doc__
are pretty much built into Python. Are those the only reserved double-underscore variables? Are there any more? Is there some place I can get a list?
Related:
- What is the common header format of Python files?
- I need __closure__ (links to this mindmap of a bunch of double-underscore variables)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想查看魔术名称是否已记录,请转到 Lib 目录并运行:
这会产生:
If you want to see magic names whether documented or not, go to the Lib directory and run:
That produces:
Python 使用的完整列表在 Python 语言参考第 3 节“数据模型”。其他每个模块都是非标准的或由第三方模块使用,并单独记录。
The complete list used by Python is given in the Python Language Reference section 3, "Data model". Every other one is non-standard or used by third-party modules and is documented separately.