Python里面所有instance应该现在__init__里面预定义
原因:
Yes, you should assign all attributes of your object in the
__init__
method.The most important reason to do this is tool support. Many Python IDEs can see the assignments in the
__init__
and use those attributes for type-based autocompletion. Sphinx-doc can list those attributes in your reference documentation.
来源:
两个讨论:
例子:
Tesorflow project in Githup
Simple is the best, 简单的就是美好的。