Python
[PEP8] When to use trailing commas
ju_young
2022. 2. 25. 17:49
728x90
- 하나의 요소로된 튜플을 만들때 마지막에 comma를 추가하고 괄호로 감싸는 것을 추천
# Correct:
FILES = ('setup.cfg',)
# Wrong:
FILES = 'setup.cfg',
- trailing comma는 나중에 list, arguments, imported items 등 확장될 것으로 예상될 때 유용
- 각 line에 trailing comma를 추가하고 괄호는 다음 줄에 닫는다.
- trailing comma와 같은 줄에 괄호를 닫는 것은 의미가 없음
# Correct:
FILES = [
'setup.cfg',
'tox.ini',
]
initialize(FILES,
error=True,
)
# Wrong:
FILES = ['setup.cfg', 'tox.ini',]
initialize(FILES, error=True,)
[reference]
https://www.python.org/dev/peps/pep-0008/#when-to-use-trailing-commas
728x90