本文へスキップ
Skillpedia
一般的なプログラミング7.8k · #12956

python-debug-execution

できること

このスキルは、AIエージェントがPythonのコードを、分かりやすいエラーの出力とともに実行してデバッグする単純な方法を説明します。AIを通してPythonのスクリプトを実行する人向けです。

使う場面

  • ✓Pythonのスクリプトが止まり、理由が分からないとき。
  • ✓スクリプト内のファイル操作が失敗し、フォルダが間違っているかもしれないとき。
  • ✓AIにフォルダの内容を一覧にさせ、ファイルが正しい場所にあるかを確認させたいとき。

スキルのリンク

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-execution/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-execution/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“スクリプトがファイルのパスで失敗し続けています。デバッグを手伝ってください。また、どのフォルダで実行されているかも見せてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、エラーの出力を取り込んでスクリプトを実行し、終了コードを表示します。スクリプトが読み書きする前に、作業ディレクトリとその中のファイルを表示する確認を加えます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Python Debug Execution Pattern

When executing Python scripts that may fail, use this pattern to surface clear error information and diagnose issues effectively.

Core Technique

1. Execute with Full Error Output

Always run Python scripts with stderr redirected to stdout and echo the exit code:

python3 script.py 2>&1 ; echo Exit code: $?

Why this works:

  • 2>&1 captures both stdout and stderr, ensuring tracebacks are visible
  • echo Exit code: $? reveals the actual exit status for debugging
  • Avoids opaque "command failed" errors that hide the real cause

2. Verify Working Directory in Script

Before any file operations in Python scripts, add working directory verification:

import os

# At the start of your script or before file operations
print(f"Current working directory: {os.getcwd()}")

# For debugging, also list directory contents
print(f"Directory contents: {os.listdir('.')}")

Why this works:

  • File not found errors often stem from incorrect working directory assumptions
  • Makes path-related failures immediately diagnosable
  • Confirms the execution context matches expectations

Complete Debugging Workflow

Step 1: Add Diagnostic Code to Script

#!/usr/bin/env python3
import os
import sys

def main():
    # Diagnostic: verify execution context
    print(f"Working directory: {os.getcwd()}")
    print(f"Python version: {sys.version}")
    print(f"Directory listing: {os.listdir('.')}")
    
    # Your actual logic here
    # ...

if __name__ == "__main__":
    main()

Step 2: Execute with Full Error Capture

python3 script.py 2>&1 ; echo Exit code: $?

Step 3: Analyze Output

Look for:

  • Traceback messages (indicate code errors)
  • Exit code (0 = success, non-zero = failure)
  • Working directory confirmation
  • Missing file/directory errors

Common Failure Patterns

Symptom Likely Cause Debug Clue
FileNotFoundError Wrong working directory Check os.getcwd() output
ModuleNotFoundError Missing dependencies Traceback shows import path
PermissionError File access issues Traceback shows file path
Silent failure (exit 0, no output) Logic bug, not crash Add print statements

When to Use This Pattern

  • Running Python scripts in automated/agent contexts
  • Debugging scripts that interact with files
  • Troubleshooting CI/CD pipeline failures
  • Any scenario where script output may be truncated or hidden
よくある質問

なぜフォルダの内容を一覧にするのですか?

どのファイルがあるかを見ると、ファイルが見つからない理由が分かることが多いからです。

特定の種類のスクリプトだけに使えますか?

いいえ。ファイルを読み書きするどのPythonのスクリプトにも当てはまります。

Pythonを知っている必要がありますか?

いいえ。エージェントがコマンドを扱い、各出力の意味を説明します。

詳細

作者による元の説明

Debug Python scripts with proper error surfacing and working directory verification

repo: HKUDS/AgentPilot

人気

GitHubのスター
7.8k
ランキング
#12956
ライセンス
MIT
更新日
2026/11/1

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル