Should Python class filenames also be camelCased?

m4jesticsun picture m4jesticsun · Feb 9, 2017 · Viewed 46.5k times · Source

I know that classes in Python are typically cased using camelCase.

Is it also the normal convention to have the file that contains the class also be camelCase'd especially if the file only contains the class?

For example, should class className also be stored in className.py instead of class_name.py?

Answer

Caitlin Quintero Weaver picture Caitlin Quintero Weaver · Feb 9, 2017

The following answer is largely sourced from this answer.

If you're going to follow PEP 8, you should stick to all-lowercase names, with optional underscores.

To quote PEP 8's naming conventions for packages & modules:

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability.

And for classes:

Class names should normally use the CapWords convention.

See this answer for the difference between a module, class and package:

A Python module is simply a Python source file, which can expose classes, functions and global variables.