一个简单的工具库 / A Eazy Tools Module
Project description
中文文档
Chinese Document
English Document use DeepSeek AI and Google Translate
There may be some inaccuracies
欢迎 💎
感谢你点击这个项目
这是一个 工具箱 / 快捷工具 类型的项目
带有 6 个函数可使用
Luci_Code_Tools 🔍
代码花费 9000+ 字符数
2026 年 5 月 9 日开始维护
27 个异常处理, 个个定制的异常返回 (触发异常时返回的操作)
许可证 📄
使用 MIT License 许可证
设备 📱 💻
早期版本 (2.1.5 及更早) 使用 Android 上的 MT 管理器 (软件开发者: Bin)
早期版本以后的版本使用 (版本 >=2.1.6) Visual Studio Code 进行编写 (软件开发商: Microsoft Corporation)
设备信息
Android 设备信息: Android 13
Windows 设备信息: Windows 10 22H2
作者 ヾ(≧▽≦*)o
作者名字叫: Luci_Code
2014 年出生 🐱
此代码的编写者 : Luci_Code
此文档的编写者 : Luci_Code
Github 链接: https://github.com/Luci-Code-2014/
代码介绍 🎮
项目文件夹 📂:
Luci_Code_tools.py | 代码主文件
200+ 行数运行的代码文件 🐱
setup.py | 上传信息
在 PyPI 上上传时传输的信息
包括 适用版本, 许可证信息等
你可以在此模块的网页界面左边部分看到他给予的信息喵🐱
README.md | 此文档
这就是你现在看到的文档喵🐱
LICENSE | 许可证 (MIT)
MIT 许可证是 目前 (2026 年) 最自由的许可证
他不要求你获得授权
他只要求在转载时能加一个来源喵🐱
主代码
27 个异常处理
包括:
结果 板块为代码中给出的结果
在原本的代码中所有异常处理的结果都为报错
错误退出是指在错误的状态的报出错误并退出
比如程序被不正确的方式报错了, 这时候就应该错误退出程序, 会被 SystemExit 捕获
| 报错 | 意思 | 结果 |
|---|---|---|
| ValueError | 输入的值与期待的值类型错误 | 重试 |
| KeyboardInterrupt | 在 Ctrl + C 时, 命令行会被中断而显示的报错 | 退出 + 提示语 |
| EOFError | 意思是 End of file , 代表输入流被关闭 | 退出 + 提示语 |
| MemoryError | 内存过高导致的错误, 比如你输入了一个极高长度的字符超过了你的内存大小 | 退出(错误退出) + 提示语 |
| SystemError | Python 解释器损坏 | 退出 + 提示语 |
| OSError | 你系统炸了 😂 (可能是系统文件损坏问题引起的错误) | 退出(错误退出) + 提示语 |
等错误, 总共有 27 种异常处理, 正常情况下 几乎不可能报错
📦 安装方式 & 导入方式
pip install Luci-Code-Tools
默认会安装最新版
你可以通过把
pip install <包名>
改成
pip install <包名>==<版本号>
来安装对应的版本
导入 & 引用
# 注: 所有方式的示例函数为 color 函数
# 导入
import Luci_Code_tools
Luci_Code_tools.color("HelloWorld", 32, None, 1, 2)
# 导入 + as
import Luci_Code_tools as lct
lct.color("HelloWorld", 32, None, 1, 2)
# 引用
from Luci_Code_tools import color
color("HelloWorld", 32, None, 1, 2)
# 引用 + as
from Luci_Code_tools import color as cl
cl("HelloWorld", 32, None, 1, 2)
参数介绍
line 的输出样式是
{
"line": 0,
"data": "Hello",
"data": "World",
"output": 2
} "output": 2 等于两个输出函数
输出效果:
HelloWorld ("Hello" 和 "World" 是两个字符串)
{
"line": 1,
"data": "Hello",
"data": "World",
"output": 2
} "output": 2 等于两个输出函数
输出效果:
Hello
(这里的空间其实不空行)
World
{
"line": 2,
"data": "Hello",
"data": "World",
"output": 2
} "output": 2 等于两个输出函数
输出效果:
Hello
(Markdown 格式限制, 中间其实有空着一行)
World
line 参数可以调更高, 但是由于篇幅限制我需要减少测试喵🐱
通过数字个性化调整空行数来提高辨识度
函数参数
我们先列出目前代码中所用的函数
函数
-
color_rgb
-
color
-
clear_screen
-
safe_input
-
safe_int
-
safe_float
所有参数
我们首先介绍 color_rgb
- color_rgb
这个函数是一个管理 RGB 彩色输出的函数, 使用 ANSI 转义序列 + 参数 完成的构建
参数包括:
data r g b mode line
- data
data 参数是控制 输入的内容 的参数
-
r
-
g
-
b
这三个参数按照 R, G, B 三个字符的顺序写, 比如 255, 0, 0 为纯红色
- mode
mode 参数是控制输出模式的参数, 具体输出模式参数表在最后
- line
line 参数输入整数, 具体信息在 "参数介绍" 部分片段
- color
此函数是一个管理 ANSI 转义序列彩色字符的函数 🤔
- data
管理在彩色字符输出时输出的字符串
- text_color
通过 ANSI 颜色码来控制输出的颜色, 不用调来调去, 详细参数在最后的参数表
- bg_color
通过 ANSI 颜色码来控制输出时背景的颜色, 详细参数在最后的参数表
- mode
通过 ANSI 转义序列的输出方式来控制输出 / 显示的方式
- line
和上一位 color_rgb 是一个意思, 都可以控制输出时间隔的行数
- clear_screen
clear_screen 没有参数, 但是我带来了函数介绍
函数介绍
此函数有:
判断系统自动使用相对应清屏命令
比如:
Android -> clear (Linux 内核)
Linux -> clear
Windows -> cls
来切换使用的清屏命令
绝对的防注入, 列表控制清屏的参数与命令
即使是没有命令行的环境 (无法使用 clear / cls 命令的环境) 也可以使用 shutil 模块来检测终端高度并输出对应的空行数
甚至不能获取到终端高度也能输出 250 个空行来 "清屏"
-
safe_input
-
safe_int
-
safe_float
这些 safe_* 的参数都是一样的:
prompt | 提示词
text_color | 提示词颜色
bg_color | 提示词背景颜色
mode | 提示词输出方式
- prompt
prompt 跟 data 参数是一个意思喵🐱
-
text_color
-
bg_color
-
mode
这三个参数和 color, color_rgb 中的这三个参数是一样的, 代表的意思相同喵🐱
参数表
前景色
| 前景色 - 值 | 效果 |
|---|---|
| 30 | 黑色 |
| 31 | 红色 |
| 32 | 绿色 |
| 33 | 黄色 |
| 34 | 蓝色 |
| 35 | 紫色 |
| 36 | 青色 |
| 37 | 白色 |
前景色 - 浅色
| 前景色 - 值 | 效果 |
|---|---|
| 90 | 深灰色 |
| 91 | 浅红色 |
| 92 | 浅绿色 |
| 93 | 浅黄色 |
| 94 | 浅蓝色 |
| 95 | 浅紫色 |
| 96 | 浅青色 |
| 97 | 浅灰色 |
背景色
| 背景色 - 值 | 效果 |
|---|---|
| 40 | 黑色 |
| 41 | 红色 |
| 42 | 绿色 |
| 43 | 黄色 |
| 44 | 蓝色 |
| 45 | 紫色 |
| 46 | 青色 |
| 47 | 白色 |
背景色 - 浅色
| 背景色 - 值 | 效果 |
|---|---|
| 100 | 深灰色 |
| 101 | 浅红色 |
| 102 | 浅绿色 |
| 103 | 浅黄色 |
| 104 | 浅蓝色 |
| 105 | 浅紫色 |
| 106 | 浅青色 |
| 107 | 纯白色 |
输出方式
| 显示方式 - 值 | 效果 |
|---|---|
| 0 | 默认 |
| 1 | 高亮 + 加粗 |
| 2 | 暗淡 |
| 3 | 斜体 (部分终端可能不支持) |
| 4 | 下划线 |
| 5 | 闪烁 |
| 6 | 快闪(部分终端可能不支持) |
| 7 | 反色(前景色与背景色互换) |
| 8 | 隐藏 |
| 9 | 删除线 |
制作人员 & 感谢名单 (以贡献程度排名从上到下)
| 人员 | 提供 |
|---|---|
| DeepSeek | 构建 & 打包 & 上传教程 |
| DeepSeek | 提供改进意见 |
| DeepSeek | 环境帮助 |
| Luci_Code | 编写 |
| Luci_Code | 打包 |
| Luci_Code | 制作 |
| Luci_Code | 构建 |
| Luci_Code | 上传 |
| Luci_Code | 构思 |
快速上手
输入输出
from Luci_Code_tools import color, safe_input
text = safe_input("请输入文本: ", 32, None, 1)
color(f"你输入了 {text}", 32, None, 1, 2)
计算器
from Luci_Code_tools import color, safe_float, safe_input
from sys import exit
color("=== 计算器 ===", 32, None, 1, 2)
while True:
num1 = safe_float("请输入第一位数字: ", 32, None, 1)
num2 = safe_float("请输入第二位数字: ", 32, None, 1)
operators = safe_input("请输入运算符(+, -, *, /, 输入 quit 退出): ")
if operators == "+":
color(f"结果为: {num1 + num2}\n==========", 32, None, 1, 2)
continue
elif operators == "-":
color(f"结果为: {num1 - num2}\n==========", 32, None, 1, 2)
continue
elif operators == "*":
color(f"结果为: {num1 * num2}\n==========", 32, None, 1, 2)
continue
elif operators == "/":
if num2 == 0:
color("除数不能等于 0\n==========", 33, None, 1, 2)
continue
else:
color(f"结果为: {num1 / num2}\n==========", 32, None, 1, 2)
continue
elif operators == "quit":
color("=== 退出成功 ===", 32, None, 1, 2)
exit(0)
else:
color("没有这个运算符!\n==========", 33, None, 1, 2)
continue
文件读写
from Luci_Code_tools import color
from os import remove
from json import load, dump, JSONDecodeError
JSON = {
"test": "This is Test content",
"test2": "This is Test content 2"
}
FILE_PATH = "user.json"
def fix_json(prompt: str) -> None:
color(prompt, 33, None, 1, 2)
with open(FILE_PATH, "w", encoding="utf-8") as f:
dump(JSON, f, ensure_ascii=False, indent=4, sort_keys=True)
color("修复成功! 请重启程序", 32, None, 1)
try:
with open(FILE_PATH, "r", encoding="utf-8") as f:
data = load(f)
except FileNotFoundError:
fix_json("文件不存在, 正在修复中...")
except JSONDecodeError:
fix_json("Json 文件格式或内容错误")
else:
content_1 = data["test"]
content_2 = data["test2"]
color(f"内容1: {content_1}\n内容2: {content_2}\n\n测试成功!", 32, None, 1, 2)
remove(FILE_PATH)
English Document
英语文档
Welcome 💎
Thanks for checking out this project
This is a toolbox / quick-utility style project
Features 6 functions for use
Luci_Code_Tools 🔍
Codebase spans over 9,000 characters
Maintenance began on May 9, 2026
27 exception handlers, each with a custom return value (the output returned when an exception is triggered)
License 📄
Uses the MIT License
Devices 📱 💻
Early versions (2.1.5 and earlier) were developed using MT Manager on Android (Developer: Bin)
Versions from 2.1.6 onwards were written using Visual Studio Code (Developer: Microsoft Corporation)
Device Information
Android device info: Android 13
Windows device info: Windows 10 22H2
Author ヾ(≧▽≦*)o
Author's name: Luci_Code
Born in 2014 🐱
Code written by: Luci_Code
Documentation written by: Luci_Code
GitHub link: https://github.com/Luci-Code-2014/
Code Overview 🎮
Project folders/files 📂:
Luci_Code_tools.py | Main code file
A script spanning over 200 lines of code 🐱
setup.py | Upload metadata
Information transmitted during PyPI upload
Includes compatible versions, license details, etc.
You can view this information on the left side of the module's webpage 🐱
README.md | This document
The very document you are reading right now 🐱
LICENSE | License (MIT)
The MIT License is currently (as of 2026) the most permissive license available
It does not require you to obtain explicit authorization
It only asks that you credit the source when redistributing 🐱
Main Code
27 exception handlers
Including:
Results The sections below describe the results defined in the code.
In the original code, all exception handling scenarios result in an error report.
Error Exit refers to raising an error due to an invalid state and subsequently terminating the program.
For instance, if the program encounters an improper error condition, it should perform an Error Exit; this is caught by SystemExit.
| Error | Meaning | Result |
|---|---|---|
| ValueError | Input value type does not match expected type | Retry |
| KeyboardInterrupt | Error displayed when the command line is interrupted (e.g., Ctrl + C) | Exit + Message |
| EOFError | End of File; indicates the input stream has been closed | Exit + Message |
| MemoryError | Error caused by excessive memory usage (e.g., inputting a string exceeding available memory) | Exit (Error Exit) + Message |
| SystemError | Python interpreter corruption | Exit + Message |
| OSError | Your system crashed 😂 (likely caused by corrupted system files) | Exit (Error Exit) + Message |
There are 27 types of exception handling in total; under normal circumstances, errors almost never occur.
📦 Installation & Import
pip install Luci-Code-Tools
This installs the latest version by default.
You can install a specific version by changing
pip install <package_name>
to
pip install <package_name>==<version_number>
Import & Reference
# Note: The example function used in all cases is the 'color' function
# Import
import Luci_Code_tools
Luci_Code_tools.color("HelloWorld", 32, None, 1, 2)
# Import + as
import Luci_Code_tools as lct
lct.color("HelloWorld", 32, None, 1, 2)
# Reference
from Luci_Code_tools import color
color("HelloWorld", 32, None, 1, 2)
# Reference + as
from Luci_Code_tools import color as cl
cl("HelloWorld", 32, None, 1, 2)
Parameter Introduction
The output style for line is:
{
"line": 0,
"data": "Hello",
"data": "World",
"output": 2
}
"output": 2 corresponds to two output functions.
Output effect:
HelloWorld ("Hello" and "World" are two separate strings)
{
"line": 1,
"data": "Hello",
"data": "World",
"output": 2
}
"output": 2 corresponds to two output functions.
Output effect:
Hello
(There is actually no blank line here)
World
{
"line": 2,
"data": "Hello",
"data": "World",
"output": 2
}
"output": 2 corresponds to two output functions.
Output effect:
Hello
(There is actually a blank line in between)
World
The line parameter can be set higher, but I need to limit the number of tests due to space constraints 🐱
Adjust the number of blank lines numerically to improve readability.
Function Parameters
Let's first list the functions currently used in the code.
Functions
-
color_rgb
-
color
-
clear_screen
-
safe_input
-
safe_int
-
safe_float
All Parameters
First, let's introduce color_rgb
- color_rgb
This function manages RGB color output; it is constructed using ANSI escape sequences + parameters.
Parameters include:
data r g b mode line
- data
The data parameter controls the content to be output.
-
r
-
g
-
b
These three parameters are specified in the order of R, G, and B; for example, 255, 0, 0 represents pure red.
- mode
The mode parameter controls the output mode; a table of specific output modes is provided at the end.
- line
The line parameter accepts an integer; specific details can be found in the "Parameter Introduction" section above.
- color
This function manages colored text using ANSI escape sequences 🤔
- data
Manages the string to be output with color formatting.
- text_color
Controls the output color using ANSI color codes; no need for complex adjustments. Detailed parameters are in the parameter table at the end.
- bg_color
Controls the background color of the output using ANSI color codes. Detailed parameters are in the parameter table at the end.
- mode
Controls the output/display style using ANSI escape sequences.
- line
Serves the same purpose as the color_rgb parameter mentioned earlier; both control the number of blank lines between outputs.
- clear_screen
clear_screen takes no arguments, but here is an introduction to the function.
Function Introduction
This function:
Automatically detects the system and uses the corresponding screen-clearing command.
For example:
Android -> clear (Linux kernel)
Linux -> clear
Windows -> cls
It switches the command used based on the OS.
Ensures absolute protection against injection attacks by using a controlled list of parameters and commands for clearing the screen.
Can use the
shutilmodule to detect terminal height and output the appropriate number of blank lines, even in environments without a command-line interface (whereclearorclscommands are unavailable).
Can output 250 blank lines to "clear the screen" even if the terminal height cannot be detected.
-
safe_input
-
safe_int
-
safe_float
These safe_* functions share the same parameters:
prompt | Prompt text
text_color | Prompt text color
bg_color | Prompt background color
mode | Prompt output style
- prompt
The prompt parameter serves the same purpose as the data parameter.
-
text_color
-
bg_color
-
mode
These three parameters are identical to the corresponding ones in color and color_rgb, serving the same function.
Parameter Table
Foreground Color
| Foreground Color - Value | Effect |
|---|---|
| 30 | Black |
| 31 | Red |
| 32 | Green |
| 33 | Yellow |
| 34 | Blue |
| 35 | Purple |
| 36 | Cyan |
| 37 | White |
Foreground Color - Light/Bright
| Foreground Color - Value | Effect |
|---|---|
| 90 | Dark gray |
| 91 | Light red |
| 92 | Light green |
| 93 | Light yellow |
| 94 | Light blue |
| 95 | Light purple |
| 96 | Light cyan |
| 97 | Light gray |
Background Color
| Background Color - Value | Effect |
|---|---|
| 40 | Black |
| 41 | Red |
| 42 | Green |
| 43 | Yellow |
| 44 | Blue |
| 45 | Purple |
| 46 | Cyan |
| 47 | White |
Background Color - Light Shades
| Background Color - Value | Effect |
|---|---|
| 100 | Dark gray |
| 101 | Light red |
| 102 | Light green |
| 103 | Light yellow |
| 104 | Light blue |
| 105 | Light purple |
| 106 | Light cyan |
| 107 | Pure white |
Output Mode
| Display Mode - Value | Effect |
|---|---|
| 0 | Default |
| 1 | Highlight + Bold |
| 2 | Dim |
| 3 | Italic (may not be supported by some terminals) |
| 4 | Underline |
| 5 | Blink |
| 6 | Rapid blink (may not be supported by some terminals) |
| 7 | Invert (swap foreground and background colors) |
| 8 | Hidden |
| 9 | Strikethrough |
Credits & Acknowledgments (Ranked by contribution level, top to bottom)
| Person/Entity | Contribution |
|---|---|
| DeepSeek | Build, packaging, and upload tutorial |
| DeepSeek | Provided improvement suggestions |
| DeepSeek | Environment help |
| Luci_Code | Writing |
| Luci_Code | Packaging |
| Luci_Code | Creation |
| Luci_Code | Building |
| Luci_Code | Uploading |
| Luci_Code | Conceptualization |
Quick Start
Input and Output
from Luci_Code_tools import color, safe_input
text = safe_input("Please enter text: ", 32, None, 1)
color(f"You entered {text}", 32, None, 1, 2)
Calculator
from Luci_Code_tools import color, safe_float, safe_input
from sys import exit
color("=== Calculator ===", 32, None, 1, 2)
while True:
num1 = safe_float("Enter the first number: ", 32, None, 1)
num2 = safe_float("Enter the second number: ", 32, None, 1)
operators = safe_input("Enter operator (+, -, *, /, type 'quit' to exit): ")
if operators == "+":
color(f"Result: {num1 + num2}\n==========", 32, None, 1, 2)
continue
elif operators == "-":
color(f"Result: {num1 - num2}\n==========", 32, None, 1, 2)
continue
elif operators == "*":
color(f"Result: {num1 * num2}\n==========", 32, None, 1, 2)
continue
elif operators == "/":
if num2 == 0:
color("Divisor cannot be zero\n==========", 33, None, 1, 2)
continue
else:
color(f"Result: {num1 / num2}\n==========", 32, None, 1, 2)
continue
elif operators == "quit":
color("=== Exit successful ===", 32, None, 1, 2)
exit(0)
else:
color("Invalid operator!\n==========", 33, None, 1, 2)
continue
File Read and Write
from Luci_Code_tools import color
from os import remove
from json import load, dump, JSONDecodeError
JSON = {
"test": "This is Test content",
"test2": "This is Test content 2"
}
FILE_PATH = "user.json"
def fix_json(prompt: str) -> None:
color(prompt, 33, None, 1, 2)
with open(FILE_PATH, "w", encoding="utf-8") as f:
dump(JSON, f, ensure_ascii=False, indent=4, sort_keys=True)
color("Repair successful! Please restart the program", 32, None, 1)
try:
with open(FILE_PATH, "r", encoding="utf-8") as f:
data = load(f)
except FileNotFoundError:
fix_json("File not found, repairing...")
except JSONDecodeError:
fix_json("JSON file format or content error")
else:
content_1 = data["test"]
content_2 = data["test2"]
color(f"Content 1: {content_1}\nContent 2: {content_2}\n\nTest successful!", 32, None, 1, 2)
remove(FILE_PATH)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 luci_code_tools-2.2.9.tar.gz.
File metadata
- Download URL: luci_code_tools-2.2.9.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c95056b4537ded9ae387bbbcf814a55964641d4de597ea1e0b784492bd20c9d1
|
|
| MD5 |
c8b18efa05793796d188b5b9b10f70f2
|
|
| BLAKE2b-256 |
62fb0a8d9b6f8455ba3785b3ba5fc0d2957fbb243565188e732f082015bd9d73
|
File details
Details for the file luci_code_tools-2.2.9-py3-none-any.whl.
File metadata
- Download URL: luci_code_tools-2.2.9-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0013880f516fcce49b4b0f67e4550a0aab593a88797792d882688bce5ceebe02
|
|
| MD5 |
91a076f2ae5b1d4ae1defe3e876edbaf
|
|
| BLAKE2b-256 |
abe1265bc6c57055bb4da6c7eb8c8572383e5bd73d823025a02f7870b88dd608
|