Skip to main content

Printing and debugging with color

Project description

cprintf

安装

pip install cprintf

使用方法

import cprintf
from time import sleep

# 设置日志级别
cprintf.set_log_level('DEBUG')  # 可选: DEBUG, INFO, WARNING, ERROR, FATAL

# 基本打印功能
cprintf.info("普通字符串")
cprintf.info('{"hello": "world", "list": [1, 2, 3]}')
cprintf.info({"hello": "world", "list": [1, 2, 3]})
cprintf.warn({"warn_key": True})
cprintf.err("这是一条错误信息", format_mode='pprint')
cprintf.fatal("This is a fatal error.")
cprintf.ok('强制使用 pprint 模式', format_mode='pprint')
cprintf.debug('强制使用 raw 模式', format_mode='raw')

# 带时间戳的日志
cprintf.info("这是一条带时间戳的信息", timestamp=True)

# 分割线
cprintf.line()
cprintf.line(char='=', length=60, color='OK')

# 自定义颜色
cprintf.custom("This is a custom color message in cyan!", "\033[96m")

# 进度条
for i in range(100):
    sleep(0.1)
    cprintf.progress_bar(i + 1, 100, prefix='进度:', suffix='完成', length=50)

# 打印表格
data = [
    [1, "Alice", 25],
    [2, "Bob", 30],
    [3, "Charlie", 35]
]
cprintf.print_table(data, headers=["ID", "Name", "Age"], color='INFO')

# 获取带颜色的字符串(不打印)
colored_str = cprintf.get_colored_string("这是一个带颜色的字符串", color='WARNING')
print(colored_str)

功能说明

  • 日志级别控制:通过 set_log_level() 设置日志级别,低于该级别的日志将不会显示
  • 时间戳:在日志信息前添加时间戳,使用 timestamp=True 参数
  • 进度条:使用 progress_bar() 方法显示进度条
  • 表格打印:使用 print_table() 方法打印整齐的表格
  • 自定义颜色:使用 custom() 方法自定义颜色,或使用 get_colored_string() 获取带颜色的字符串
  • 格式化模式:支持 rawjsonpprintauto 四种格式化模式

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cprintf-0.0.11.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cprintf-0.0.11-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file cprintf-0.0.11.tar.gz.

File metadata

  • Download URL: cprintf-0.0.11.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.0

File hashes

Hashes for cprintf-0.0.11.tar.gz
Algorithm Hash digest
SHA256 84adfb894a6a384166a70552bce19f79f03f7987677403ce2f6dd841fb142ae5
MD5 1280b931072c26e68c54bd5d2c8b5f3a
BLAKE2b-256 b57288d60eef671d6a6bfe4ffb24ee9efce59c863492e6e906830829ad3831f7

See more details on using hashes here.

File details

Details for the file cprintf-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: cprintf-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.0

File hashes

Hashes for cprintf-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 6a9450d7572ce5bad4560401ba0b3d25a1f2e49895a768caa0c7d3e08d24d83a
MD5 cee91d7e2a861ece3b5a54b495cb2a2e
BLAKE2b-256 34d46366f751803305715922ec04b2fced7258b3dab26825b4dcd65d13dd1c02

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page