Pular para o conteúdo
Skillpedia
Código em geral7,8 mil · #12956

python-debug-execution

O que ela faz

Esta skill explica uma forma simples de o agente de IA executar e depurar código Python com saída de erro clara. É para pessoas que executam scripts Python por meio de uma IA.

Quando usar

  • ✓Quando um script Python para e você não consegue entender o motivo.
  • ✓Quando as operações com arquivos de um script falham e a pasta pode estar errada.
  • ✓Quando você quer que a IA liste o conteúdo da pasta para confirmar que os arquivos estão onde deveriam.

Link da skill

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

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-execution/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Meu script continua falhando em um caminho de arquivo. Me ajude a depurá-lo e mostre em qual pasta ele está sendo executado.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

O agente executa o script com a saída de erro capturada e imprime o código de saída. Acrescenta verificações que imprimem o diretório de trabalho e os arquivos nele antes de o script ler ou gravar qualquer coisa.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do 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
Perguntas frequentes

Por que listar o conteúdo da pasta?

Ver quais arquivos estão presentes costuma mostrar por que um arquivo não é encontrado.

Isso funciona só para um tipo de script?

Não. As etapas valem para qualquer script Python que leia ou grave arquivos.

Preciso saber Python?

Não. O agente executa os comandos e explica o que cada saída significa.

Detalhes

Descrição original do autor

Debug Python scripts with proper error surfacing and working directory verification

repo: HKUDS/AgentPilot

Popularidade

Estrelas no GitHub
7,8 mil
Posição no ranking
#12956
Licença
MIT
Atualizada em
01/11/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas