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?

Community
  • 1
  • 1
Calaf
  • 10,113
  • 15
  • 57
  • 120
  • See this [similar question](http://programmers.stackexchange.com/questions/308972/python-file-naming-convention) on Programmers. – Delgan Jul 12 '16 at 19:17
  • "Best Practices" really relate to technical methods that have some objective evidence supporting their benefits. Naming conventions are rather arbitrary. – Galik Jul 12 '16 at 19:18
  • It's best practice to group multiple classes in one module, so the module is normally not named after one class. – Daniel Jul 12 '16 at 19:21
  • Why are you applying a Python style guide to C++? – Captain Obvlious Jul 12 '16 at 19:22
  • 1
    @CaptainObvlious I wasn't. I inserted headings to make it clear. – Calaf Jul 12 '16 at 19:27
  • @Daniel 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. – Calaf Jul 12 '16 at 19:30
  • Figured as much. I have removed the C++ tag since it doesn't apply here. – Captain Obvlious Jul 12 '16 at 20:20

1 Answers1

17

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

lafferc
  • 2,741
  • 3
  • 24
  • 37