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.9.tar.gz (6.8 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.9-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cprintf-0.0.9.tar.gz
  • Upload date:
  • Size: 6.8 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.9.tar.gz
Algorithm Hash digest
SHA256 0e690f797415c6b4d1347c6fe4783189d2698b3b01ad5381d2fbb28b92c1f3c9
MD5 988abf5a8a038448828a849b3440e79c
BLAKE2b-256 d8e39b024073d4537759a55babde3b4b1b638418d187928c1dc01b2a45ed2f17

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cprintf-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 7.9 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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 7175c18d5003f5ecfabb25ee28dc1aa66f5f97d88a1a2911332ab327ffa9ac93
MD5 928e8826b042ea88b42982f37593ce24
BLAKE2b-256 b6f70dd28d1641dcb49e52edbd553a29bfc673b58154c8ca48841b3738d94b78

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