Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you PEP 8-name a class whose name is an acronym?

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:

Almost without exception, class names use the CapWords convention. Classes for internal use have a leading underscore in addition.

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.

like image 540
Escualo Avatar asked May 17 '10 23:05

Escualo


People also ask

Which choice is PEP 8 compliant as the name of a class?

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: Almost without exception, class names use the CapWords convention.

How do you name a class?

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).


1 Answers

PEP-8 does cover this (at least partially):

Note: When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus HTTPServerError is better than HttpServerError.

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.

like image 141
Dan Head Avatar answered Oct 19 '22 05:10

Dan Head