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()获取带颜色的字符串 - 格式化模式:支持
raw、json、pprint和auto四种格式化模式
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.7.tar.gz
(4.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cprintf-0.0.7.tar.gz.
File metadata
- Download URL: cprintf-0.0.7.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5b0dd4e0a8530b79f94f9cf754d63252ef4a497be5c6475a0e2f40b6bc84bd9
|
|
| MD5 |
b717dc94257c8883dba59c2694b0ddc3
|
|
| BLAKE2b-256 |
cc045dd540eebf0d5a16147e47de2f6bef7d28bc3d4f5d9080bf3251bbcf2f39
|
File details
Details for the file cprintf-0.0.7-py3-none-any.whl.
File metadata
- Download URL: cprintf-0.0.7-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac7e35f9700fc09ca857987930d2bf67859ed862bc1f546ca30e9164d0127312
|
|
| MD5 |
2bbbc418774aaccaa968d04900b29259
|
|
| BLAKE2b-256 |
a5715aafbc885721e47b4de20c32176f749add20234fe82a402a0329f3763b2d
|