Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 598ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
i

icecream

Recently created Least recently created Recently updated Least recently updated

timmy / 錯誤與除錯輸出配置

Last active 5 hours ago debugging error-handling icecream logging pretty-errors python traceback

此程式使用 pretty_errors 改善錯誤輸出,並使用 icecream (ic) 進行簡潔的除錯訊息輸出,方便開發人員快速定位錯誤與分析變數內容,提高程式除錯效率。

1 0 0 2
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 / 使用 icecream 進行偵錯並透過上下文管理控制輸出

Last active 5 hours ago context-manager debugging disable-logging icecream python temporary-disable

這段 Python 程式碼 使用 contextlib.contextmanager 來建立一個 自訂的上下文管理器 (ic_disabled()),用於 暫時停用 icecream (ic) 的輸出,並在 離開上下文後復原原始狀態。

0 0 0 1
1 # 引用python內建模組contextlib中的contextmanager
2 from contextlib import contextmanager
3
4 # 將icecream模組簡稱為ic
5 from icecream import ic # 引用icecream模組
6
7 # 設定icecream的輸出選項,包含上下文
8 ic.configureOutput(includeContext=True)
9
10 # 定義ic_disabled函式為一個上下文管理器