最後活躍 10 months ago
此程式使用 pretty_errors 改善錯誤輸出,並使用 icecream (ic) 進行簡潔的除錯訊息輸出,方便開發人員快速定位錯誤與分析變數內容,提高程式除錯效率。
| 1 | import pretty_errors |
| 2 | from icecream import ic |
| 3 | |
| 4 | |
| 5 | def configure_pretty_errors() -> None: |
| 6 | """ |
| 7 | 配置 pretty_errors 庫,用於更好的錯誤輸出。 |
| 8 | |
| 9 | 不需要任何參數。 |
| 10 | """ |
timmy / 使用 Streamlit 與 Pydantic 建立使用者資訊展示
0 喜歡
0 分支
1 檔案
最後活躍 10 months ago
這段程式碼使用 pydantic 來定義使用者模型,並且透過 Streamlit 在網頁上顯示使用者資訊,同時 pretty_errors 提供美觀的錯誤訊息格式。
| 1 | from datetime import date |
| 2 | |
| 3 | import pretty_errors |
| 4 | import streamlit as st |
| 5 | from pydantic import BaseModel, Field |
| 6 | |
| 7 | |
| 8 | class User(BaseModel): |
| 9 | id: int |
| 10 | name: str |
timmy / 使用 pretty_errors 美化 Python 錯誤訊息
0 喜歡
0 分支
1 檔案
最後活躍 10 months ago
此程式透過 pretty_errors 讓錯誤訊息更易讀,並觸發除零錯誤 (ZeroDivisionError),適用於開發除錯與錯誤診斷。
| 1 | import pretty_errors |
| 2 | |
| 3 | |
| 4 | def division_by_zero(): |
| 5 | 1 / 0 |
| 6 | |
| 7 | |
| 8 | if __name__ == "__main__": |
| 9 | division_by_zero() |
上一頁
下一頁