Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalization of filenames storing Python classes

Tags:

python

pep

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?

like image 796
Calaf Avatar asked Jul 12 '16 19:07

Calaf


People also ask

Should python class files be capitalized?

Short answer: No. Longer answer: should be all lower case and underscores as needed. From PEP8 "Package and Module Names": Modules should have short, all-lowercase names.

How do you capitalize file names in python?

To capitalize the first letter we will use the title() function in python. The title function in python is the Python String Method which is used to convert the first character in each word to Uppercase and the remaining characters to Lowercase in the string and returns the new string.

Should python file names be lowercase?

Naming Convention for Functions in Python While writing the Python function name, we should only use all lower case characters. No uppercase characters should be used.


1 Answers

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

like image 69
lafferc Avatar answered Oct 15 '22 04:10

lafferc