본문으로 건너뛰기
Skillpedia
일반 코딩7.8k · #12956

python-debug-execution

하는 일

이 스킬은 AI로 Python 코드를 실행하고 디버깅할 때 명확한 오류 출력을 얻는 간단한 방법을 설명합니다. AI를 통해 Python 스크립트를 실행하는 사람에게 맞습니다.

사용하는 경우

  • ✓Python 스크립트가 멈췄는데 이유를 알 수 없을 때.
  • ✓스크립트의 파일 작업이 실패하고 폴더가 잘못되었을 수 있을 때.
  • ✓파일이 제대로 있는지 확인하려고 폴더 내용을 나열하고 싶은 경우.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-execution/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 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

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬