termcolor 라이브러리는 터미널에서 컬러 출력이 가능하도록 해주는 Python 패키지입니다.
아래 예제는 termcolor를 사용하여 다양한 색상의 텍스트를 출력하는 코드입니다.
from termcolor import colored
# 기본 사용법
print(colored("Hello, World!", "red")) # 빨간색 출력
print(colored("Python is awesome!", "green")) # 초록색 출력
# 배경색 추가
print(colored("Warning message!", "yellow", "on_red")) # 빨간 배경에 노란 글씨
# 다양한 속성 추가
print(colored("Bold Text", "blue", attrs=["bold"])) # 볼드체(굵은 글씨)
print(colored("Underlined Text", "cyan", attrs=["underline"])) # 밑줄 추가
# 여러 속성 조합
print(colored("Styled Text", "magenta", "on_white", ["bold", "underline"]))
colored() 함수의 주요 인자:
• text: 출력할 문자열
• color: 텍스트 색상 (red, green, yellow, blue, magenta, cyan, white)
• on_color: 배경 색상 (on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white)
• attrs: 속성 (bold, dark, underline, blink, reverse, concealed)
설치 방법:
termcolor 라이브러리가 없다면 아래 명령어로 설치할 수 있습니다.
pip install termcolor
이제 실행하면 컬러풀한 출력이 터미널에서 보일 거예요! 🎨🚀
'Areas > [Lang] Python' 카테고리의 다른 글
python을 새로운 패키지 관리자 uv (0) | 2025.03.30 |
---|---|
[pandas] melt() 사용법 (0) | 2025.03.09 |
TypedDict란? (0) | 2025.02.20 |
파이썬에 설치된 패키지와 클래스를 탐색하는 방법 (0) | 2025.02.09 |
맥에서 파이썬 여러 버전 관리하는 법 (0) | 2025.02.09 |
파이썬 의존성을 해결하는 방법 (0) | 2025.02.08 |
pip command 리스트 (1) | 2019.11.09 |