Opengist

Explore

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

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

introspection

Recently created Least recently created Recently updated Least recently updated

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

Last active 6 hours ago debugging inspect introspection python reflection

inspect 模組允許在執行時動態獲取函式、類別、模組的結構與資訊,適用於 除錯、程式碼分析、自動文件生成、動態調試 等場景。

0 0 0 3
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}")