Saltar al contenido
Skillpedia
Programación general7,8 mil · #12957

python-debug-pattern

Qué hace

Esta skill da al agente de IA una forma repetible de ejecutar scripts de Python y averiguar por qué fallan. Está pensada para quien necesita detalles claros de los errores de un script.

Cuándo usarla

  • ✓Cuando un script de Python falla y solo ves un mensaje opaco.
  • ✓Cuando un script escribe en un archivo y necesitas confirmar dónde se guardó.
  • ✓Cuando quieres que la IA compare una ejecución correcta con una fallida.

Link de la skill

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

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-pattern/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Ejecuta mi script process_data y dime exactamente por qué falla, incluido el error completo.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

El agente ejecuta el script capturando stderr e imprime el código de salida. Registra la carpeta de trabajo y la ruta absoluta de cualquier archivo en el que el script escriba.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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
Preguntas frecuentes

¿Qué es una traza?

Una traza es la lista de pasos que dio Python antes de un error, y muestra dónde se produjo el problema.

¿Por qué registrar la ruta absoluta de un archivo de salida?

Muestra exactamente dónde se guardó el archivo, lo que ayuda cuando no lo encuentras.

¿Puedo usarlo sin editar mi script?

Sí. El comando de ejecución por sí solo muestra los errores, aunque las líneas de diagnóstico ayudan más.

Detalles

Descripción original del autor

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

repo: HKUDS/AgentPilot

Popularidad

Estrellas en GitHub
7,8 mil
Posición en el ranking
#12957
Licencia
MIT
Actualizada
1/11/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas