[Python] 파이썬 출력 문자 색 변경하기

2023. 4. 4. 21:31·Python/Open Source
반응형

[Python] 파이썬 출력 문자 색 변경하기 (Python print with color)

  • 파이썬 문자 혹은 데이터 출력시에 색깔과 함께 이미지처럼 출력하는 방법

GitHub 주소

  • https://github.com/sanggi-wjg/color_print

Install

pip install colorful_print

Usage 1

import sys
from colorful_print import color

a = [1, 'a', 2.3]
b = (4, 'b', 5.6)

color.black('Print Black', a, b)
color.red('Print Red', a, b)
color.green('Print Green', a, b)
color.yellow('Print Yellow', a, b)
color.blue('Print Blue', a, b)
color.magenta('Print Magenta', a, b)
color.cyan('Print Cyan', a, b)
color.white('Print White', a, b)
sys.stdout.write("\n")

color.red('Print Red', a, b)
color.green('Print Bold Green', a, b, bold=True)
color.yellow('Print Bold Italic Yellow', a, b, bold=True, italic=True)
color.blue('Print Bold Italic Underline Blue', a, b, bold=True, italic=True, underline=True)
color.magenta('Print Bold Italic Underline StrikeOut Magenta', a, b, bold=True, italic=True, underline=True, strike_out=True)
color.cyan('Print Bold Italic Underline Reverse Cyan', a, b, bold=True, italic=True, underline=True, reverse=True)
color.white('Print Bold Italic Underline StrikeOut Reverse White', a, b, bold=True, italic=True, underline=True, strike_out=True, reverse=True)
sys.stdout.write("\n")

color.black('Print Black', a, b, sep='\t\t', end='\n\n', flush=True)
color.red('Print Red', a, b, sep='\t\t', end='\n\n', flush=True)
color.green('Print Green', a, b, sep='\t\t', end='\n\n', flush=True)

Usage 2

from colorful_print import color

def colorful_dispatcher(c: str, msg: str, *args, **kwargs):
    dispatch = getattr(color, c)
    dispatch(msg, *args, **kwargs)

def red(msg: str, *args, **kwargs):
    colorful_dispatcher('red', msg, *args, **kwargs)

def yellow(msg: str, *args, **kwargs):
    colorful_dispatcher('yellow', msg, *args, **kwargs)

red('123', 456, italic=True)
yellow('789', 123.456, italic=True, bold=True)
728x90
반응형
저작자표시 비영리 변경금지 (새창열림)
'Python/Open Source' 카테고리의 다른 글
  • [Locust] 2. Locust를 통한 언어와 프레임워크 별 테스트
  • [Locust] 1. Locust 부하 테스트 툴(load testing tool)
  • ChatGPT를 이용한 간단한 Web App 만들기 (python, streamlit)
  • [Python] Colorful print
상쾌한기분
상쾌한기분
  • 상쾌한기분
    상쾌한기분
    상쾌한기분
  • 전체
    오늘
    어제
    • 분류 전체보기 (250)
      • Python (44)
        • Python (26)
        • Django (6)
        • Flask (4)
        • Open Source (6)
      • Kotlin & Java (5)
        • Spring (2)
        • 프로젝트 (1)
      • Go (11)
      • Database (24)
        • MySQL (21)
        • Redis (3)
      • Infrastructure (2)
        • CDC (4)
        • Kafka (5)
        • Prometheus (2)
        • Fluentd (11)
        • Docker (1)
        • Airflow (2)
        • VPN (2)
      • IT (25)
        • AI (9)
        • Langchain (8)
        • Web (18)
        • Git (8)
        • 리팩토링 (9)
        • Micro Service Architecture (8)
        • Clean Code (16)
        • Design Pattern (0)
        • 수학 (1)
        • 알고리즘 (14)
      • OS (14)
        • Centos (10)
        • Ubuntu (3)
        • Mac (1)
      • Search Engine (2)
        • ElasticSearch (1)
        • Lucene Solr (1)
      • PHP (2)
        • Laravel (1)
        • Codeigniter (1)
  • 블로그 메뉴

    • Github 방문
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    ollama
    http
    Kafka
    Redis
    python
    백준
    MYSQL
    fluentd
    Golang
    CDC
    go
    오블완
    Langchain
    파이썬
    LLM
    티스토리챌린지
    performance
    docker
    git
    prompt
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
상쾌한기분
[Python] 파이썬 출력 문자 색 변경하기
상단으로

티스토리툴바