我知道在其他语言中( C# 、 JAVA 、 ...)制作 "private" 是一种很好的风格。方法(使用两个下划线)static如果可能的话。 有Python的推荐吗?
我宁愿不让它们静态,因为它们只是私有(private)的(我不想将它们移动到实用程序类,并且它们与性能无关),并且我想避免装饰器使我的代码困惑。另一方面,静态代码分析器告诉我这样做(并且我想以“Pythonic”方式编写代码)。
最佳答案
简短的回答是你几乎不应该在 Python 中使用静态方法。他们是added by mistake .
I meant to implement class methods but at first I didn't understand them and accidentally implemented static methods first. - Guido van Rossum
您几乎肯定可以使用类方法或实例方法来实现您想要的目的。
更多关于为什么 Python 中的静态方法大多无用的信息 here .
关于Python:如果可能的话,使私有(private)类方法始终静态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36980441/