在Python代码中,当命名类、方法和变量时,处理众所周知的首字母缩略词的规范方法是什么?在
例如,考虑一个处理RSS提要的类。宁愿这样:
class RSSClassOne:
def RSSMethod(self):
self.RSS_variable = True
class ClassRSSTwo:
def MethodRSS(self):
self.variable_RSS = True
或者这个:
^{pr2}$也就是说,保持首字母缩略词大写还是保留PEP 008的建议更重要?在
编辑:从答案中,我得出结论,这将是一条出路:
class RSSClassOne:
def rss_method(self):
self.rss_variable = True
class ClassRSSTwo:
def method_rss(self):
self.variable_rss = True
嗯,事实证明PEP8已经讨论了这个主题here:
换句话说,Python对包含首字母缩略词的名称的约定是:
在类名中保持首字母大写(通常是Python中唯一使用CapWords的部分)。
在其他地方,使它们小写以符合另一个naming conventions。
下面是使用^{} module 的演示:
我不认为第一个有什么问题。由于首字母缩略词代表一系列单词,在Python
class
中,在每个单词的开头CamelCase
中,将首字母(单词)大写是完全可以的。在因此,第一个代码示例可能比第二个更符合Python代码的样式指南。简而言之,第一个因为PEP8构象非常重要。:)
同时请记住,有时有时(尽管很少)这些规则可能会稍微弯曲。这可以被认为是其中之一。在
我想说,遵循pep8中的建议是与编码风格相关的第一件事。在
相关问题 更多 >
编程相关推荐