# Scenario Description Example Reference
1 Imports Imports should usually be on separate lines.
import os
Imports are always put at the top of the file. https://www.python.org/dev/pe
import sys
Imports should be grouped in the following order: <empty line>
ps/pep-0008/#imports
1. standard library imports from numpy import array
2. related third party imports <empty line>
3. local application/library specific imports from sdk import sdkfile
You should put a blank line between each group of
imports.
2 Indentation Indentation level will be set to four spaces. If you are https://www.python.org/dev/pe
if condition:
using tab, check one tab is equal to four spaces in your <four spaces># code ps/pep-0008/#indentation
editor. else:
<four spaces># code
3 Line Length Limited all lines to a maximum of 79 characters. https://www.python.org/dev/pe
ps/pep-0008/#maximum-line-
PS: Check your editor to set maximum of 79 characters length
that will help you to indicate when your code goes more
than 80 characters.
4 Block Block comments starts with a # and single space https://www.python.org/dev/pe
#<single space> comments
Comments ps/pep-0008/#block-comments
5 Inline Inline Comments is on the same line statements and https://www.python.org/dev/pe
code< two spaces># <single space>
Comments should be separated by at least two spaces, after # single ps/pep-0008/#inline-comments
comments
space is required.
6 Doc String Doc string comments is required for common or parent https://www.python.org/dev/pe
def function():
modules, functions, classes and methods. Doc string ps/pep-0008/#documentation-
“””
comments should usually be within the triple quotes. your comments strings
“””
return None
7 Naming Class name contains Cap Words and should not be https://www.python.org/dev/pe
separated by underscore. Function name should be class ClassName(objects) ps/pep-0008/#naming-
Convention
lowercase if required separated by underscore. Variable def function_name(); return None conventions
should be lowercase if required separated by underscore.
vsrisble_one = ‘naming convention’
8 Blank Lines Top level functions and class definition are surrounded by https://www.python.org/dev/pe
two blank lines. Class methods are surrounded by single # empty line ps/pep-0008/#blank-lines
# empty line
blank line. Always at the end of the file only one blank def function();return None
line is required. # empty line
# empty line
class ClassName:
# empty line
def __init__(self):
# code
# empty line
9 White White space is required after the comma and colon https://www.python.org/dev/pe
(Specific in Python dictionary), Operator is required a dict<space>=<space>{‘key’:<space>‘val ps/pep-0008/#whitespace-in-
Spaces
ue’,<space>’key_1’:<space>‘value_1’}
space, but space is not required for keyword argument or expressions-and-statements
tuple<space>=<space>(‘value’,<space>‘
a default parameter value. value_1’, <space>‘value_2’)
deffunc(arg<nospace>=<nospace>Non
e);return arg
10 Constants Constants variable written in all capital letters with each https://www.python.org/dev/pe
words separated by underscore. CONSTANTS_VALUE = 0 ps/pep-0008/#constants
Inspect Your Code:
- Open your project using PyCharm.
- From the Main Menu choose Code – Inspect Code. The Specify Inspection Scope dialog box opens.
- In the Inspection Scope area, specify the file or whole project or directory.
- Click, OK to run code analysis.
- The Inspection result box will open at the bottom of the editor with options like,
o Python XXX warnings XXX weak warnings
o Spelling XXX typos
- Select the Python XXX warnings XXX weak warnings, this will list the types of warnings and weak warnings. If there is any PEP-0008
warnings or weak warnings will be displayed like,
o PEP 8 coding style violation XX weak warnings
o PEP 8 naming convention violation XX weak warnings
- Select the option, all the warnings will be listed based on file.
- Reference: https://www.jetbrains.com/help/pycharm/running-inspections.html