首页 > 编程语言 > 详细

Python里面所有instance应该现在__init__里面预定义

时间:2017-11-26 10:47:35      阅读:321      评论:0      收藏:0      [点我收藏+]

原因:

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.

来源:

两个讨论:

https://softwareengineering.stackexchange.com/questions/357937/is-it-really-correct-to-declare-all-instance-attributes-in-init?noredirect=1&lq=1#comment774986_357941

https://softwareengineering.stackexchange.com/questions/254576/is-it-a-good-practice-to-declare-instance-variables-as-none-in-a-class-in-python

例子:

Tesorflow project in Githup

技术分享图片

Python里面所有instance应该现在__init__里面预定义

原文:http://www.cnblogs.com/easonbolg/p/7898330.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!