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

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página