All gists matching topic pretty-errors

timmy / 錯誤與除錯輸出配置

1 likes
0 forks
2 files
Last active 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 """
Last active 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
Last active 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()
Newer Older