-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Kyung-Su Kang edited this page May 21, 2024
·
2 revisions
파이썬/C++/JavaScript 코딩 스타일 가이드
스페이스(space)와 탭(tab)을 섞어서 사용하지 않는다. VSCode를 사용할 시 탭의 스페이스 길이는 4이다.
한 줄에 하나의 문장만 허용한다. 한 줄은 최대 79자까지지만 파이토치, PyQT 사용 시 flake8 옵션으로 100자까지 늘린다.
class PythonClass(SuperClass) -> None:
"""This is an example."""
def __init__(self):
super().__init__()
pass SYMBOLIC_CONSTANT: int = 1문자열 할당 시 작은따옴표를 사용한다.
variable_name: str = ''
def is_variable(variable: List):
pass_num_images: int = 128
def _is_number(num: Any):
pass파이썬 기본 명령어 또는 외부 명령어 충돌을 피하기 위해 언더바를 문자열 마지막에 사용한다.
input_: Tensor = torch.Tensor()C/C++ 확장 모듈은 밑줄로 시작한다.
^^
# Wrong
a, b, = 10, 'ten'# Correct:
spam(ham[1], {eggs: 2})
# Wrong:
spam( ham[ 1 ], { eggs: 2 } )
# Correct:
foo = (0,)
# Wrong:
bar = (0, )
# Correct:
x = 1
y = 2
long_variable = 3
# Wrong:
x = 1
y = 2
long_variable = 3income = (gross_wages +
taxable_interest +
(dividends - qualified_dividends) -
ira_deduction -
student_loan_interest)
income = (
gross_wages
+ taxable_interest
+ (dividends - qualified_dividends)
- ira_deduction
- student_loan_interest
)import os
from collections import defaultdict
import numpy as np
obj: Dict[str, int] = {'one': 1}
obj: Dict[str, int] = {
'one': 1,
'two': 2,
'three': 3,
}def function(a: int, b: int, c: int):
pass- 데이터형 확인하기
- 조건 확인하기
def function() -> None:
pass
def function() -> int:
return 1- 순회하기
- 콜백 함수의 스코프
인라인(inline) 주석은 사용하지 않는다. 부득이한 경우, 두 칸 스페이스 후 작성한다.
variable_name: str = '' # 주석def function1():
pass
def function2():
passfrom typing import List, Optional
from torch import nn, Tensor
class Model(nn.Module):
def __init__(self, num_classes: int, use_amp: Optional = None):
self.num_classes = num_classes
self.use_amp = use_amp
def forward(self, inputs: List[Tensor]) -> Tensor
outputs = self.model(inputs)
return outputs변수에 정수
num_images: int = 10
images: List[str] = ['001.jpg', '002.jpg']
num_epochs: int = 3
step: Tuple[int] = [100, 200, 500]info_path
image_dir
image_idsstd::string info_pathimport numpy as np
box: np.ndarray[np.float64] = np.array([10.1, 20.2, 30.1, 40.2], dtype=np.float64)