Python: code analysis with pylint

Ckmobile
2 min readNov 30, 2022
Photo by Artturi Jalli on Unsplash

To use the pylint we need to install pylint at terminal.

pip install pylint

Then we can create a file, such as “main.py”.

def add(a,b):
return a+b

print(add(1,3))

Go to the terminal and type “pylint main.py”

************* Module main copy
main copy.py:5:0: C0305: Trailing newlines (trailing-newlines)
main copy.py:1:0: C0114: Missing module docstring (missing-module-docstring)
main copy.py:1:0: C0103: Argument name "a" doesn't conform to snake_case naming style (invalid-name)
main copy.py:1:0: C0103: Argument name "b" doesn't conform to snake_case naming style (invalid-name)
main copy.py:1:0: C0116: Missing function or method docstring (missing-function-docstring)

-------------------------------------
Your code has been rated at -10.00/10

We can see the above

For these two issues, which is about the naming of the argument a and b,

we can change it to num_1 and num_2, which conform to snake case.

main copy.py:1:0: C0103: Argument name "a" doesn't conform to snake_case naming style (invalid-name)      
main copy.py:1:0: C0103: Argument name "b" doesn't conform to snake_case naming style (invalid-name)

For “Missing module docstring (missing-module-docstring)”, we can add the comment to describe this module, such as

"""author : Peter"""

For the “Missing function or method docstring (missing-function-docstring)”, we can add the description of the function.

def add(num_1,num_2):
"""return the sum"""

return num_1+num_2

At last, to deal with the issue “Trailing newlines (trailing-newlines)”, we can add an “ENTER” after the last line of code.

By the way, if you are using VS Code, you can also use the extension called “Pylint”, it will show the issues instantly with curly lines.

--

--