Capitalization of filenames storing Python classes
Asked Answered
V

1

8

C++

I use a rigorous rule of capitalizing class names.

Over many years I tried to use the somewhat inconsistent rule of using lowercase names for the files—when writing in C++.

For example, class Stopwatch would be in the files stopwatch.hpp and stopwatch.cpp.

I am not sure at this point how or why I found that this is awkward, but I'm reasonably sure that it turned out to be. I use exactly the same case for the files. One benefit is that it helps avoid annoying issues in version control on OS X.

Python

PEP 8 recommends lowercase names for modules and packages. It makes no recommendations regarding filenames holding classes.

Is there such a recommendation or some best practices?

Vestpocket answered 12/7, 2016 at 19:14 Comment(7)
See this similar question on Programmers.Lamellar
"Best Practices" really relate to technical methods that have some objective evidence supporting their benefits. Naming conventions are rather arbitrary.Barrio
It's best practice to group multiple classes in one module, so the module is normally not named after one class.Gromyko
Why are you applying a Python style guide to C++?Sp
@CaptainObvlious I wasn't. I inserted headings to make it clear.Vestpocket
@Gromyko Ah! So that's the catch. I was also moving a rigorous rule I apply in C++ to Python: Never put two classes in the same file.Vestpocket
Figured as much. I have removed the C++ tag since it doesn't apply here.Sp
E
18

In python each file is a module so to follow PEP8 your code should be as follows

from stopwatch import Stopwatch

Therefore the file should be stopwatch.py

Elevon answered 12/7, 2016 at 19:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.