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

python-debug-pattern

하는 일

이 스킬은 AI 에이전트에게 Python 스크립트를 반복 가능하게 실행하고 실패 이유를 찾는 방법을 줍니다. 스크립트의 자세한 오류 정보가 필요한 사람에게 맞습니다.

사용하는 경우

  • ✓Python 스크립트가 실패했는데 불명확한 메시지만 보일 때.
  • ✓스크립트가 파일을 쓰는데 결과물이 어디 갔는지 확인해야 할 때.
  • ✓정상 실행과 실패 실행을 비교하고 싶은 경우.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-pattern/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-pattern/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 process_data 스크립트를 실행하고, 전체 오류를 포함해서 정확히 왜 실패하는지 알려 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 표준 오류를 잡아 스크립트를 실행하고 종료 코드를 출력합니다. 작업 폴더와 스크립트가 쓰는 파일의 절대 경로를 기록합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Python Debug Pattern

This skill provides a reusable pattern for debugging Python script execution failures. It ensures you capture actual tracebacks instead of opaque errors and verify the working directory before file operations.

Core Technique

1. Execute Python Scripts with Full Error Capture

When running Python scripts, always use this command pattern to surface actual tracebacks:

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

Why this works:

  • 2>&1 redirects stderr to stdout, capturing both regular output and errors
  • ; echo Exit code: $? displays the actual exit code after execution
  • This reveals the full Python traceback instead of opaque failure messages

Examples:

# Good: Full error capture
python3 process_data.py 2>&1 ; echo Exit code: $?

# Bad: Opaque error (no stderr capture, no exit code)
python3 process_data.py

2. Verify Working Directory Before File Operations

Before any file read/write operations in Python, verify the current working directory:

import os

# At script start, log the working directory
print(f"Working directory: {os.getcwd()}")

# For file operations, use absolute paths or log the resolved path
file_path = "output/result.csv"
abs_path = os.path.abspath(file_path)
print(f"Writing to: {abs_path}")

Why this works:

  • Many failures occur because scripts run from unexpected directories
  • Logging the working directory immediately surfaces path-related issues
  • Absolute paths prevent ambiguity in file operations

Full example script structure:

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

def main():
    # Debug: verify working directory
    print(f"Working directory: {os.getcwd()}", file=sys.stderr)
    
    # Debug: list directory contents if dealing with files
    print(f"Directory contents: {os.listdir('.')}", file=sys.stderr)
    
    # Your actual logic here
    # ...

if __name__ == "__main__":
    main()

When to Apply This Pattern

  • Python script fails with an opaque error message
  • File operations (read/write) fail unexpectedly
  • Script works locally but fails in automated execution
  • Debugging CI/CD pipeline failures
  • Investigating "file not found" or permission errors

Quick Checklist

  • Run script with 2>&1 ; echo Exit code: $? pattern
  • Add os.getcwd() logging at script start
  • Use os.path.abspath() for file paths
  • Log directory contents with os.listdir('.') if relevant
  • Check for missing dependencies (capture full traceback)

Common Failure Modes This Pattern Surfaces

Symptom Without Pattern With Pattern
File not found "Error: failed" Full traceback showing exact path attempted
Permission denied Script exits silently stderr shows permission error
Missing module Opaque exit ImportError with module name
Wrong directory Confusing path errors cwd logged, reveals directory mismatch
자주 묻는 질문

트레이스백은 무엇인가요?

Python이 오류 전에 거친 단계들의 목록이며, 문제가 어디서 생겼는지 보여 줍니다.

출력 파일의 절대 경로를 기록하는 이유는 무엇인가요?

파일이 정확히 어디에 저장되었는지 보여 주므로, 파일을 찾지 못할 때 도움이 됩니다.

스크립트를 고치지 않고 쓸 수 있나요?

네, 실행 명령만으로도 오류가 보이지만 진단 줄을 넣으면 더 도움이 됩니다.

상세 정보

작성자의 원본 설명

Debug Python script execution failures by capturing full output with exit codes and verifying working directory before file operations

repo: HKUDS/AgentPilot

인기도

GitHub 스타
7.8k
순위
#12957
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬