Coding Rules - KeremDlkmn/appstore-profile-scraper GitHub Wiki
Formatting
Indentation
Use 4 spaces per indentation level.
# Correct:
# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
var_three, var_four)
# Add 4 spaces (an extra level of indentation) to distinguish arguments from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
# Hanging indents should add a level.
foo = long_function_name(
var_one, var_two,
var_three, var_four)
# Wrong:
# Arguments on first line forbidden when not using vertical alignment.
foo = long_function_name(var_one, var_two,
var_three, var_four)
# Further indentation required as indentation is not distinguishable.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
IF - ELSE Statement
When the conditional part of an if-statement is long enough to require that it be written across multiple lines, it's worth noting that the combination of a two character keyword (i.e. if), plus a single space, plus an opening parenthesis creates a natural 4-space indent for the subsequent lines of the multiline conditional.
#Correct
if (this_is_one_thing
and that_is_another_thing):
do_something()
# Wrong
# No extra indentation.
if (this_is_one_thing and
that_is_another_thing):
do_something()
Functions
There must be at least 1 and no more than 2 spaces between functions.
# Correct
def A(self):
# operations...
def B(self):
# operations...
2 spaces can be left as below
# Correct
def A(self):
# operations...
def B(self):
# operations...
Imports
Imports should usually be on separate lines:
# Correct:
import os
import sys
# Wrong:
import sys, os
It's okay to say this though:
# Correct:
from subprocess import Popen, PIPE