Should Python class filenames also be camelCased?

前端 未结 4 1487
别那么骄傲
别那么骄傲 2021-02-02 05:10

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 especia

4条回答
  •  梦谈多话
    2021-02-02 06:06

    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.

提交回复
热议问题