Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
Should Python class filenames also be camelCased?

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?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report

0

The official convention is to use all lower case for file names (as others have already stated). The reason, however, has not been mentioned...

Since Python works cross platform (and it is common to use it in that manner), but file systems vary in the use of casing, it is better to just eliminate alternate cases. In Linux, for instance, it is possible to have MyClass.py and myclass.py in the same directory. That is not so in Windows!

On a related note, if you have MyClass.py and myclass.py in a git repo, or even just change the casing on the same file, git can act funky when you push/pull across from Linux and Windows.

And, while barely on topic, but in the same vein, SQL has these same issues where different standards and configurations may or may not allow UpperCases on table names.

I, personally, find it more pleasant to read TitleCasing / camelCasing even on filenames, but when you do anything that can work cross platform it's safest not to.

over 4 years ago · Santiago Trujillo Report

0

My question is, 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

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. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

If you're unclear what a module is:

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!