问题描述
我尝试遵守Python代码的样式指南(也称为)。因此,命名类的首选方法是使用CamelCase:
如果我的类名由两个字符组成,我如何与PEP 8保持一致首字母缩略词(英语应该大写)。例如,如果我的类名是'NASA JPL',你会叫什么名字呢?:
class NASAJPL 1
class NASA_JPL():#2
class NasaJpl():#3
我使用#1,但它看起来很奇怪; #3看起来很奇怪,#2似乎违反PEP 8.
想法?
/ p>
非常感谢您的回答。虽然这个问题没有一个正确的答案,我从你的见解中获益良多。
我将使用#3:更好地始终是错误的(缩写为 Title
)不一致。
再次感谢。
确实涵盖了这一点(至少部分):
b $ b
我会读的意思是 NASAJPL()
是根据PEP-8推荐的名字。
个人我会找到 NasaJpl()
,因为大写字母容易标记单词边界并给出命名一个独特的形状。
I try to adhere to the style guide for Python code (also known as PEP 8). Accordingly, the preferred way to name a class is using CamelCase:
How can I be consistent with PEP 8 if my class name is formed by two acronyms (which in proper English should be capitalized). For instance, if my class name was 'NASA JPL', what would you name it?:
class NASAJPL(): # 1
class NASA_JPL(): # 2
class NasaJpl(): # 3
I am using #1, but it looks weird; #3 looks weird too, and #2 seems to violate PEP 8.
Thoughts?
EDIT:
Many thanks for your answers. While the question really does not have a 'correct' answer, I benefited a lot from your insights.
I will be resorting to a #3: better to be consistently wrong (in the sense of having an acronym/abbreviation as a Title
) than inconsistently right.
Thanks again.
PEP-8 does cover this (at least partially):
Which I would read to mean that NASAJPL()
is the recommended name according to PEP-8.
Personally I'd find NasaJpl()
the easiest to scan since the upper case letters easily mark word boundaries and give the name a distinctive shape.
这篇关于你如何PEP 8名称一个类的名称是首字母缩写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!