YH Data Scientist의 정리글
PEP 8 - Codes Lay-out - Maximum Line Length 본문
이번 포스트는 코드 레이아웃 중 최대 라인 길이에 대해서 정리하고자 합니다.
아래는 PEP 8 - Style Guide for Python Code 을 번역한 내용입니다.
Maximum Line Length
Limit all lines to a maximum of 79 characters.
모든 줄은 최대 79 자로 제한됩니다.
For flowing long blocks of text with fewer structural restrictions (docstrings or comments), the line length should be limited to 72 characters.
구조적 제한이 적은 긴 텍스트 블록 (문서 문자열 또는 주석)은, 라인 길이를 72 자로 제한해야 합니다.
Limiting the required editor window width makes it possible to have several files open side-by-side, and works well when using code review tools that present the two versions in adjacent columns.
편집기 창 너비를 제한하면 여러 파일을 나란히 열 수 있으며, 인접한 열에 두 버전을 표시하는 코드 검토 도구를 사용할 때 잘 작동합니다.
-> 예를 들면 WinMerge 같은 코드 검토 도구를 이용할 때, 오류 없이 잘 작동한다는 의미인 듯합니다.
The default wrapping in most tools disrupts the visual structure of the code, making it more difficult to understand. The limits are chosen to avoid wrapping in editors with the window width set to 80, even if the tool places a marker glyph in the final column when wrapping lines. Some web based tools may not offer dynamic line wrapping at all.
대부분의 도구에서 기본 줄 바꿈은 코드의 시각적 구조를 방해하므로 이해하기가 어렵습니다. 줄 바꿈 할 때 도구가 최종 열에 마커 글리프를 배치하더라도 창 너비가 80으로 설정된 편집기에서 줄 바꿈을 피하기 위해 한계가 선택됩니다. 일부 웹 기반 도구는 동적 줄 바꿈을 전혀 제공하지 않을 수 있습니다.
- line wrap(자동 줄 바꿈) : 문자열의 행을 자동으로 다음 줄에 보이게 하여, 보이는 화면보다 긴 문장이 잘리지 않고 모든 내용을 볼 수 있게 하는 것을 말합니다.
-> 보통의 도구들은 자동 줄 바꿈을 하는데, 파이썬의 경우 자동 줄 바꿈을 하면 가독성을 떨어뜨리기 때문에 이를 피함.
Some teams strongly prefer a longer line length. For code maintained exclusively or primarily by a team that can reach agreement on this issue, it is okay to increase the line length limit up to 99 characters, provided that comments and docstrings are still wrapped at 72 characters.
일부 팀은 더 긴 줄 길이를 선호합니다. 이 문제에 대해 합의에 도달할 수 있는 팀이 독점적으로 또는 주로 유지 관리하는 코드의 경우 주석과 문서 문자열이 여전히 72 자로 줄 바꿈 되어 있으면 줄 길이 제한을 99 자까지 늘릴 수 있습니다.
The Python standard library is conservative and requires limiting lines to 79 characters (and docstrings/comments to 72).
파이썬 표준 라이브러리는 보수적이며 줄을 79 자로 제한해야 합니다 (docstrings / comments는 72로 제한).
The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.
긴 줄을 줄 바꿈 하는 가장 좋은 방법은 괄호 안에 파이썬의 묵시적 줄 연속을 사용하는 것입니다. 긴 줄은 표현식을 괄호로 묶어 여러 줄로 나눌 수 있습니다. 연속된 라인에 백 슬래시를 사용하는 것보다 우선적으로 사용해야 합니다.
Backslashes may still be appropriate at times. For example, long, multiple
with-statements cannot use implicit continuation, so backslashes are acceptable:
백 슬래시는 여전히 적절한 경우가 있습니다. 예를 들어 길고 여러 개의 with 문은 암시 적 연속을 사용할 수 없으므로 백 슬래시를 사용할 수 있습니다.
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())
Another such case is with assert statements.
또 다른 경우는 assert 문이 있습니다.
Make sure to indent the continued line appropriately.
연속 줄을 적절히 들여 쓰십시오.
정리
- 줄의 길이는 79자, DocString 또는 주석의 경우 72자 제한합니다.
- 긴 줄 바꿈은 백 슬래시를 사용하는 것보다 괄호를 사용하는 것을 우선해야 합니다.
- 백 슬래시는 with문과 assert문의 경우 사용됩니다.
Contents
- Introduction
- A Foolish Consistency is the Hobgoblin of Little Minds
- Code Lay-out
- Indentation
- Tabs or Spaces?
- Maximum Line Length
- Should a Line Break Before or After a Binary Operator?
- Blank Lines
- Source File Encoding
- Imports
- Module Level Dunder Names
- String Quotes
- Whitespace in Expressions and Statements
- When to Use Trailing Commas
- Comments
- Naming Conventions
- Programming Recommendations
- References
- Copyright
Reference
https://www.python.org/dev/peps/pep-0008/#maximum-line-length
https://ko.wikipedia.org/wiki/%EC%9E%90%EB%8F%99_%EC%A4%84_%EB%B0%94%EA%BF%88
'파이썬' 카테고리의 다른 글
PEP 8 - Codes Lay-out - Blank Lines (0) | 2020.03.23 |
---|---|
PEP 8 - Codes Lay-out - Should a Line Break Before or After a Binary Operator? (0) | 2020.03.22 |
PEP 8 - Codes Lay-out - Tabs or Spaces? (0) | 2020.03.17 |
PEP 8 - Code Lay-out - Indentation (0) | 2020.03.17 |
PEP 8 - A Foolish Consistency is the Hobgoblin of Little Minds (0) | 2020.03.17 |