가독성이 중요합니다
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
if (this_is_one_thing
and that_is_another_thing):
do_something()
my_list = [
1, 2, 3,
4, 5, 6,
]
with open('/path/to/some/file/you/want/to/read') as file_1, \
open('/path/to/some/file/being/written', 'w') as file_2:
file_2.write(file_1.read())
income = (gross_wages
+ taxable_interest
+ (dividends - qualified_dividends)
- ira_deduction
- student_loan_interest)
# Wrong:
spam( ham[ 1 ], { eggs: 2 } )
bar = (0, )
ham[1: 9], ham[1 :9]
# Correct:
spam(ham[1], {eggs: 2})
foo = (0,)
ham[1:9], ham[1:9:3]
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)
# Wrong:
def munge(input:AnyStr): ...
def munge()->PosInt: ...
# Correct:
def munge(input: AnyStr): ...
def munge() -> PosInt: ...
import os
import sys
from subprocess import Popen, PIPE
# Correct:
FILES = [
'setup.cfg',
'tox.ini',
]
initialize(FILES,
error=True,
)
x = x + 1 # Compensate for border
CapWords
CapWords 또는 CamelCase 시작 단어를 대문자로 쓴다.
단, 두문자어를 사용할 때 두문자어의 모든 문자를 대문자로 사용한다. 따라서 HttpServerError보다 HTTPServerError이 낫다.
from typing import TypeVar
VT_co = TypeVar('VT_co', covariant=True)
KT_contra = TypeVar('KT_contra', contravariant=True)