Python name mangling

后端 未结 11 2347
天命终不由人
天命终不由人 2020-11-22 05:31

In other languages, a general guideline that helps produce better code is always make everything as hidden as possible. If in doubt about whether a variable should be privat

11条回答
  •  半阙折子戏
    2020-11-22 06:08

    The chosen answer does a good job of explaining how properties remove the need for private attributes, but I would also add that functions at the module level remove the need for private methods.

    If you turn a method into a function at the module level, you remove the opportunity for subclasses to override it. Moving some functionality to the module level is more Pythonic than trying to hide methods with name mangling.

提交回复
热议问题