这个项目提供了一个完整的Python标准异常中英文对照数据库,包含41个异常、50条错误消息,帮助中文开发者更好地理解和解决Python错误。
- 📚 完整覆盖: 41个Python标准异常,涵盖9大分类
- 🌐 中英对照: 准确的中文翻译和详细解释
- 💡 实用示例: 每个异常包含触发场景、示例代码和解决方案
- 🔍 智能搜索: 支持完整错误日志解析和多种搜索方式
- 📊 结构化数据: JSON格式,便于集成和二次开发
- 🎨 优雅界面: 简洁的Web界面,响应式设计
├── python_errors_data.json # 核心数据文件 (41个异常)
├── index.html # Web展示界面
├── vscode-downloader.html # VS Code插件下载器
├── favicon.ico # 网站图标
├── error_lookup.py # 命令行查询工具
├── validate_data.py # 数据验证工具
├── UI-Design-System.md # UI设计系统文档
└── README.md # 项目说明
- 异常总数: 41个
- 分类数量: 9个
- 错误消息: 50条
- 数据版本: 1.0.0
- 基础异常 (9个): Exception, RuntimeError, StopIteration, AssertionError等
- 算术错误 (4个): ZeroDivisionError, OverflowError, ArithmeticError等
- 类型和值错误 (5个): TypeError, ValueError, AttributeError, NameError等
- 查找错误 (3个): IndexError, KeyError, LookupError
- 语法错误 (3个): SyntaxError, IndentationError, TabError
- 系统错误 (9个): FileNotFoundError, PermissionError, OSError等
- 导入错误 (2个): ImportError, ModuleNotFoundError
- Unicode错误 (3个): UnicodeError, UnicodeDecodeError, UnicodeEncodeError
- 警告 (3个): Warning, UserWarning, DeprecationWarning
{
"version": "1.0.0",
"last_updated": "2025-01-18",
"categories": [
{
"id": "category_id",
"name_en": "English Category Name",
"name_zh": "中文分类名",
"description_zh": "分类描述"
}
],
"exceptions": [
{
"id": "unique_identifier",
"exception_name": "ExceptionName",
"category_id": "category_id",
"description_en": "English description",
"description_zh": "中文描述",
"inheritance": ["ParentException", "BaseException"],
"common_messages": [
{
"message_en": "English error message",
"message_zh": "中文错误消息",
"scenario": "出现场景描述",
"example_code": "触发错误的代码示例",
"solution": "解决方案和建议"
}
],
"related_exceptions": ["RelatedExceptionName"],
"tags": ["tag1", "tag2", "tag3"]
}
]
}
- id: 唯一标识符,用于内部引用
- exception_name: Python异常类名
- category_id: 所属分类ID
- description_en: 英文描述
- description_zh: 中文描述
- inheritance: 继承关系数组
- common_messages: 常见错误消息数组
- related_exceptions: 相关异常名称数组
- tags: 标签数组,用于分类和搜索
- message_en: 英文错误消息
- message_zh: 中文翻译
- scenario: 出现场景
- example_code: 触发代码示例
- solution: 解决方案
直接打开 index.html
文件即可在浏览器中使用完整功能。
支持多种搜索方式:
完整错误日志搜索
# 直接粘贴完整错误日志
Traceback (most recent call last):
File "example.py", line 5, in <module>
result = 10 / 0
ZeroDivisionError: division by zero
异常名称搜索
ZeroDivisionError
ValueError
IndexError
错误消息搜索
division by zero
list index out of range
name 'x' is not defined
中文关键词搜索
除零错误
索引超出
模块未找到
- 点击分类按钮快速筛选异常
- 支持9个主要分类
- 实时更新结果数量
每个异常显示:
- 异常名称和分类
- 中英文描述
- 常见错误消息
- 触发场景
- 示例代码
- 解决方案
- 相关标签
- 支持桌面、平板、手机
- 自适应布局
- 触摸友好的交互
python error_lookup.py
支持的查询方式:
- 输入异常名称:
ValueError
- 输入错误消息片段:
division by zero
- 查看所有分类:
categories
- 按分类查询:
arithmetic
python validate_data.py
验证内容:
- JSON格式正确性
- 数据完整性检查
- 生成统计信息
- 检查引用关系
import json
# 加载数据
with open('python_errors_data.json', 'r', encoding='utf-8') as f:
data = json.load(f)
# 查找特定异常
def find_exception(exception_name):
for exc in data['exceptions']:
if exc['exception_name'] == exception_name:
return exc
return None
# 按分类查找
def find_by_category(category_id):
return [exc for exc in data['exceptions']
if exc['category_id'] == category_id]
# 搜索错误消息
def search_error_message(query):
results = []
for exc in data['exceptions']:
for msg in exc['common_messages']:
if query.lower() in msg['message_en'].lower():
results.append((exc, msg))
return results
# 使用示例
error = find_exception('ZeroDivisionError')
print(f"中文描述: {error['description_zh']}")
arithmetic_errors = find_by_category('arithmetic')
print(f"算术错误共 {len(arithmetic_errors)} 个")
// 加载数据
async function loadErrorData() {
const response = await fetch('python_errors_data.json');
return await response.json();
}
// 查找异常
function findException(data, exceptionName) {
return data.exceptions.find(exc =>
exc.exception_name === exceptionName
);
}
// 搜索功能
function searchExceptions(data, query) {
const lowerQuery = query.toLowerCase();
return data.exceptions.filter(exc =>
exc.exception_name.toLowerCase().includes(lowerQuery) ||
exc.description_zh.includes(query) ||
exc.common_messages.some(msg =>
msg.message_en.toLowerCase().includes(lowerQuery)
)
);
}
// 使用示例
loadErrorData().then(data => {
const error = findException(data, 'ValueError');
console.log('中文描述:', error.description_zh);
const results = searchExceptions(data, 'division');
console.log('搜索结果:', results.length);
});
# 错误代码
result = 10 / 0
# 完整错误日志
Traceback (most recent call last):
File "example.py", line 1, in <module>
result = 10 / 0
ZeroDivisionError: division by zero
# 中文翻译
# 除零错误:除法运算中分母为零
# 解决方案
if denominator != 0:
result = numerator / denominator
else:
print("错误:分母不能为零")
# 错误代码
number = int('abc')
# 完整错误日志
Traceback (most recent call last):
File "example.py", line 1, in <module>
number = int('abc')
ValueError: invalid literal for int() with base 10: 'abc'
# 中文翻译
# 值错误:int()函数在基数10下的无效字面量:'abc'
# 解决方案
try:
number = int(user_input)
except ValueError:
print("请输入有效的数字")
# 错误代码
my_list = [1, 2, 3]
value = my_list[5]
# 完整错误日志
Traceback (most recent call last):
File "example.py", line 2, in <module>
value = my_list[5]
IndexError: list index out of range
# 中文翻译
# 索引错误:列表索引超出范围
# 解决方案
if index < len(my_list):
value = my_list[index]
else:
print("索引超出范围")
# 错误代码
import requests
# 完整错误日志
Traceback (most recent call last):
File "example.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
# 中文翻译
# 模块未找到错误:没有名为 'requests' 的模块
# 解决方案
# 安装缺失的模块
pip install requests
本项目采用独特的简朴优雅设计风格:
- 直角美学: 所有元素使用直角设计,体现工程师的理性美
- 衬线字体: 使用Google Noto Serif SC,提供优雅的阅读体验
- 双层边框: 外层页面边框 + 内层内容边框的层次设计
- 黑白灰配色: 简洁的色彩系统,专注内容本身
- 响应式设计: 支持桌面、平板、手机三种屏幕
- 无圆角设计: 所有按钮、输入框、卡片都使用直角
- CSS变量系统: 完整的设计令牌系统
- 性能优化: 字体预加载、防抖搜索等优化
详细的UI设计系统文档请参考:UI-Design-System.md
项目还包含一个独立的VS Code插件下载器 (vscode-downloader.html
):
- 输入VS Code Marketplace链接
- 直接下载VSIX文件
- 支持离线安装
- 相同的UI设计风格
# 直接部署到任何静态网站托管服务
# 如 GitHub Pages, Netlify, Vercel 等
# 只需上传 HTML 和 JSON 文件即可
// 可以轻松集成到现有项目中
fetch('python_errors_data.json')
.then(response => response.json())
.then(data => {
// 使用异常数据
console.log(`共有 ${data.exceptions.length} 个异常`);
});
-- JSON数据可以轻松导入到各种数据库
-- 支持 MongoDB, PostgreSQL, MySQL 等
- 验证工具: 内置数据完整性检查
- 格式规范: 统一的JSON数据格式
- 版本控制: 数据版本号和更新日期
- 测试覆盖: 完整的功能测试
欢迎贡献新的异常数据或改进现有翻译!
- Fork 这个项目
- 创建新的分支
- 添加或修改异常数据
- 运行
python validate_data.py
验证数据 - 提交 Pull Request
{
"id": "unique_id",
"exception_name": "ExceptionName",
"category_id": "existing_category",
"description_en": "Clear English description",
"description_zh": "准确的中文描述",
"inheritance": ["ParentException"],
"common_messages": [
{
"message_en": "Actual error message",
"message_zh": "准确的中文翻译",
"scenario": "具体的使用场景",
"example_code": "可运行的示例代码",
"solution": "实用的解决方案"
}
],
"related_exceptions": ["RelatedExceptionName"],
"tags": ["descriptive", "tags"]
}
MIT License - 详见 LICENSE 文件
- 提交 Issue: 报告问题或建议改进
- Pull Request: 贡献代码或数据
- 讨论: 在 Issues 中讨论新功能
💡 提示: 这个项目专注于Python标准库异常。对于第三方库的异常,建议查阅相应库的官方文档。