다른 명령
파이썬 개발 추천기능 TOP10
- 파이썬 개발을 더 효율적이고 편리하게 만들어주는 기능(혹은 개념) 10가지를 소개합니다.
- 초보부터 중급 개발자까지 알면 정말 유용한 것들입니다.
가상환경 (venv / virtualenv)
이유: 프로젝트마다 다른 라이브러리 버전을 관리할 수 있음
python -m venv venv source venv/bin/activate # (Linux/macOS) venv\Scripts\activate # (Windows)
f-string (Python 3.6+)
이유: 문자열 포매팅을 간결하고 읽기 쉽게
name = "Alice" print(f"Hello, {name}!") # → Hello, Alice!
리스트 컴프리헨션
이유: 반복문 + 조건문을 한 줄로
squares = [x**2 for x in range(10) if x % 2 == 0]
데코레이터 (@decorator)
이유: 함수 실행 전/후 공통 로직을 깔끔하게 분리
def logger(func): def wrapper(*args, **kwargs): print("Before") result = func(*args, **kwargs) print("After") return result return wrapper @logger def hello(): print("Hello")
컨텍스트 매니저 (with 문)
이유: 파일, DB 연결, 락 등 자원 자동 정리
with open("file.txt", "r") as f: data = f.read()
enumerate() 와 zip()
이유: 반복문에서 인덱스 혹은 여러 리스트 병렬 처리
for i, v in enumerate(["a", "b", "c"]): print(i, v) for name, age in zip(["Tom", "Ann"], [30, 25]): print(f"{name} is {age}")
pathlib (os.path보다 간결한 파일 경로 처리)
from pathlib import Path p = Path("some/file.txt") if p.exists(): print(p.read_text())
type hint + mypy
이유: 정적 타입 체크로 에러 예방, 협업에 도움
def greet(name: str) -> str: return f"Hello, {name}"
argparse / typer
이유: CLI 앱 개발에 강력한 도구
import argparse parser = argparse.ArgumentParser() parser.add_argument("name") args = parser.parse_args() print(f"Hello, {args.name}")
logging 모듈
이유: print() 대신 로깅으로 디버깅 + 파일 저장 + 레벨별 출력
import logging logging.basicConfig(level=logging.INFO) logging.info("This is an info message.")
추가 기능
기능 설명 functools.lru_cache 함수 결과 캐싱 (속도 향상) dataclasses 모델 정의 간결하게 itertools, collections 고급 반복자/자료구조 pytest 테스트 자동화 ipython 대화형 개발환경 강화