Luci_Code_Tools
介绍:
给初学者制作的 Python 工具库, 基于 Python 3.13.3 制作
安装 & 导入
pip install Luci-Code-Tools
from Luci_code_tools import *
# 或者
import Luci_code_tools
内容
函数
safe_* = safe_input, safe_int, safe_float
| 名称 | 作用 | 参数 |
|---|---|---|
| color | 输出ANSI彩色字符 | data, text_color, bg_color, mode, newline |
| color_rgb | 输出RGB彩色字符 | data, r, g, b, mode, newline |
| clear_screen | 可跨平台的清屏 | None (没有参数) |
| safe_* | 安全的输入, 防止Ctrl + C和输入流关闭等报错 | prompt, text_color, bg_color, mode |
提示: 参数需要按照顺序填
用法
color()
color 函数有 5 个参数, 你可以选填
1.data, data 参数就仅仅是输出的内容而已
2.text_color, text_color 参数可以让输入有颜色, 参数表见其他部分段
3.bg_color, bg_color 全称 background_color, 用于管理输出的背景颜色
4.mode, mode 参数用于管理输出的格式, 参数表见其他部分段
5.newline, newline 参数只有 True 和 False, 默认为 True, 测试:
""" newline 参数测试 """
# newline = False
"""
输出内容-1
输出内容-2
输入: a
if 跳转的输出
"""
# newline = True
"""
输出内容-1
输出内容-2
输入:a
if 跳转的输出
"""
# newline 让输出变得更加美观, 可分辨
color_rgb()
color_rgb 有 5 个参数, 分别是data, r, g, b, newline
newline 和 data 的用法和之前的一样, 这里不过多赘述
r, g, b, r, g, b 参数使用 RGB 标准显示彩色, r, g, b 是字面意思, 让你填入 rgb 值, 按顺序填
clear_screen()
clear_screen源码
def clear_screen() -> None: # 清屏: 兼容版
""" 跨平台兼容清屏 """
try: # 检测环境
if platform == "win32": # 环境为 Windows
run(['cmd', '/c', 'cls']) # 安全: 使用列表命令, 防注入
else: # 包括 MacOS, Linux (Android 也是 Linux 列)
run(['clear'], check=False) # check = 遇到错误我自己来, 别报错
except Exception: # 非交互式环境 (.py 打包.exe类环境等没有cmd命令的环境)
print("\n" * 200) # 手动清屏
clear_screen 可以直接使用, 无需参数, 自动适配平台并运行相应的 清屏命令
清屏命令:
""" Windows系统: **cls**, MacOS / Linux: **clear** """
safe_input, safe_int, safe_float
这三条命令我会逐条讲解:
- safe_input
顾名思义: 安全的输入字符, 用处为防止用户 Ctrl + C 和 输入流停止 而造成的报错
用法: prompt, text_color, bg_color, mode
此处的 text_color, bg_color, mode 的用法和之前的 color 函数没有区别, prompt 就相当于 data
- safe_int / safe_float
由于这两条命令的用法相同我就放在一起讲了
参数: 和 safe_input 的相同
作用: 既然是输入数字我们就要防止用户输入字符, 不然会触发 ValueError, 所以代码中有 try - except ValueError, KeyboardInterrupt, EOFError 的防范, ValueError 输入错误会重新输入, KeyboardInterrupt / EOFError 就和之前一样
其他
ANSI常用序列 提示: 90-97 为亮色前景色,100-107 为亮色背景色
| 前景色 | 效果 |
|---|---|
| 30 | 黑色 |
| 31 | 红色 |
| 32 | 绿色 |
| 33 | 黄色 |
| 34 | 蓝色 |
| 35 | 紫色 |
| 36 | 青色 |
| 37 | 白色 |
| 显示方式 | 效果 |
|---|---|
| 0 | 默认 |
| 1 | 粗体 + 高亮 |
| 2 | 暗淡 |
| 3 | 斜体(部分终端不支持) |
| 4 | 下划线 |
| 5 | 闪烁 |
| 6 | 快闪(部分终端不支持) |
| 7 | 反色(前景色与背景色互换) |
| 8 | 隐藏 |
| 9 | 删除线 |
| 背景色 | 效果 |
|---|---|
| 40 | 黑色 |
| 41 | 红色 |
| 42 | 绿色 |
| 43 | 黄色 |
| 44 | 蓝色 |
| 45 | 紫色 |
| 46 | 青色 |
| 47 | 白色 |
制作者 & 感谢名单
| 作者 | 分工 |
|---|---|
| DeepSeek | 检查 |
| DeepSeek | 改进 |
| Luci_Code | 代码 |
| Luci_Code | 文档 |
| Luci_Code | 思路 |
| Luci_Code | 上传 |
感谢
<感谢您的阅读,我是Luci_Code, 一名2014年出生的开发者 >
Metadata
Release files for luci-code-tools 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| luci_code_tools-2.0.0.tar.gz | 8.1 kB | Without provenance | Details for luci_code_tools-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| luci_code_tools-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for luci_code_tools-2.0.0-py3-none-any.whl |
Total release size: 16.4 kB
Release files / luci_code_tools-2.0.0.tar.gz
| Download URL | luci_code_tools-2.0.0.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
009bff7b811d45f6262036b5e5183671e29004bbc496a0a98a6743f7751ac785
|
|
BLAKE2b-256 checksum How to use checksums |
4d46318d7d4e3b6f7bd9d016ba5acc272641efedab1435d295cb5702aaa35c89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / luci_code_tools-2.0.0-py3-none-any.whl
| Download URL | luci_code_tools-2.0.0-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
200cf8472ba0ff699463342f00a417c89491648362bd35f5fcc42881d7181fd8
|
|
BLAKE2b-256 checksum How to use checksums |
f56fdaaa3e93db03a22dc6c70bf6a47fc307449a69a06658fd02b8875c33aeae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for luci-code-tools 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.