python class design (staticmethod vs method)

后端 未结 3 1105
轻奢々
轻奢々 2021-01-12 10:40

What\'s the nicer way for methods that don\'t need any passed information (object instance or class) because for example they just do a simple conversion. @staticmet

3条回答
  •  臣服心动
    2021-01-12 11:18

    Any methods that do not use names from the object namespace should by classmethods, and those that do not use names from the class namespace either - staticmetdods, or even be put on the module level as functions.

    When the actual object method is used, the expected behavior is that some other attrubutes/methods from the same object will be accessed.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题