All gists matching topic introspection

timmy / 使用 inspect 來獲取函式與類別的詳細資訊

0 curtidas
0 bifurcações
3 arquivos
Última atividade 9 months ago
inspect 模組允許在執行時動態獲取函式、類別、模組的結構與資訊,適用於 除錯、程式碼分析、自動文件生成、動態調試 等場景。
1 import inspect
2
3 def example_function(a: int, b: str = "default") -> bool:
4 """示範函式,回傳 True 或 False"""
5 return bool(a)
6
7 # 獲取函式參數
8 signature = inspect.signature(example_function)
9 print(f"函式簽名: {signature}")
Próximo Anterior