Yes. Python has several style guides called PEP (Python Enhancement Proposals). In particular, PEP 8 brings details on how to correctly name each type of identifier.
Reads:
Modules should have short, all-lowercase Names. Underscores can be used in the module name if it improves readability.
Or, in free translation:
Modules should have short names and in lower case. Underscores (_
) can be used in the module name if this improves readability.
Therefore, detalhecompra.py
and detalhe_compra.py
are the two names allowed by the Style Guide.
Classes
For classes, however, the rule is different. The same document brings the following:
Class Names should normally use the Capwords Convention.
The naming Convention for functions may be used Instead in cases Where the interface is documented and used primarily as a callable.
Or, in free translation:
Class names should normally use the Capwords convention (or Pascalcase).
The naming convention for functions can be used in cases where the interface is documented and used primarily as a callable.
So it’s common to have a file detalhe_compra.py
containing the class DetalheCompra
. The import gets like this:
from detalhe_compra import DetalheCompra
This, of course, also happens in stdlibs:
from typing import NewType
Héliton, thank you so much for the answer, but I’m still having a question. This same pattern applies when we’re talking about classes?
– Guilherme Bigois
@Guilhermebigois, I added the part about classes :)
– Héliton Martins