Do you often see CamelCase in Python methods and functions?

The PEP 8 Style Guide (Python) says that method names must be lowercase, and sometimes method_names can have embedded underscores. Do experienced Python programmers often come up with CamelCase methods (with leading capital)?

+4
source share
6 answers

In my experience, module naming conventions depend on the following factors:

  • If this is a just-written, Python-only module, or if authors especially care about the "Pythonic code" (quite often!), Then naming usually follows the guidelines in the Python Style Guide.
  • Python beginners often stick to their favorite style, especially if they have Java / C # / ....
  • Some companies prefer a consistent naming convention in different languages.
  • Some Python modules adapt APIs from other languages ​​(especially Java in streaming and xml.dom modules), including a naming style.
  • Python associations for C / C ++ libraries usually contain the original name (e.g. camelCase for PyQt or PascalCase for VTK)

I think the last thing is the most common way to find PascalCase in Python code.

+6
source

I was known for reclaiming a camel in Python that just came from Java. However, this was not. I prefer the cap_name style "method_name".

One Python library that I know of that probably has camel-based method names is the xml.dom package and its subpackages (e.g. xml.dom.minidom).

+3
source

I used camelCase quite often for method names (I use underscored_names for attributes). The main reason I got this habit is probably because I used Qt.

It would probably be easier if Python enforced a naming convention and four space indents ... style is the stuff .

+1
source

I personally prefer not to use camelCase in Python (or generally my other daily use language is C), but I have seen this. I had to do this once because we used a mixed codebase (some Python and a lot of previously written Matlab code), and the Matlab code used camelCase, although I'm not sure why, since Matlab seems to frown on the camel case.

+1
source

In my experience, yes, some libraries use camelCase, but not the most common one.

I personally recommend following the python standard (as defined in PEP008), the reason is very simple: everyone with a different programming language can "impose" their own code style, and this is quite dangerous, imagine a java fan and a php fan writing python code together ... may be interesting.

However, if there is already a proposed standard, why not follow it? I mean, in java everyone uses camelCase, why? but simply because it is an agreement.

Finally, you have cool tools like pylint that are configured by default to check the syntax of PEP008.

+1
source

Several libraries have this convention. Many programmers come from the background that PascalCase uses for method names (the Pascal Case is what you are actually referring to, this is a special case of the camelCase lead capital).

This is not true in the python style guide, so I recommend not writing code this way.

0
source

Source: https://habr.com/ru/post/1333766/


All Articles