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.10.tar.gz (6.5 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.10-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cprintf-0.0.10.tar.gz
  • Upload date:
  • Size: 6.5 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.10.tar.gz
Algorithm Hash digest
SHA256 b77df435a76d3beeadb1e3912e8bc7d9582a66b83660ba61a1d6c0135bfe4a19
MD5 9b885c990a6f753fcb36a1594dc98b0c
BLAKE2b-256 91535d977d3a92a4499ad8fd8daa19f55c5291d06b8cbb59f646ce0cb636daf8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cprintf-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 7.5 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.10-py3-none-any.whl
Algorithm Hash digest
SHA256 285fa207562d2f9f36b47aa2ee7e32542e73fe9e082ff8efb14faf1320f8c32a
MD5 483543b2350c54a1e2ee2e01dfad7ba7
BLAKE2b-256 5db275b90f20626baf3507be3eaf0d7a8440c73f6254a53bb022bf3553b9793a

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