全部 新建

user:thomas 由使用者建立的 Gists

title:mygist Gists 的標題

filename:myfile.txt Gists 的檔案名稱

extension:yml Gists 的副檔名

language:go Gists 的程式語言

topic:homelab gists with given topic

登錄


全部 新建 登錄

All gists matching topic disable-logging

倒序排序 創建
順序排序 創建
倒序排序 更新
順序排序 更新

timmy / 使用 icecream 進行偵錯並透過上下文管理控制輸出

0 喜歡
0 分支
1 檔案
最後活躍 10 months ago
這段 Python 程式碼 使用 contextlib.contextmanager 來建立一個 自訂的上下文管理器 (ic_disabled()),用於 暫時停用 icecream (ic) 的輸出,並在 離開上下文後復原原始狀態。
context-manager debugging disable-logging icecream python temporary-disable
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函式為一個上下文管理器
上一頁 下一頁

由 Opengist 提供支持 ⋅ Load: 13ms⋅

繁體中文
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文