Langsung ke konten
Skillpedia
Pemrograman umum7.8k · #12956

python-debug-execution

Fungsinya

Skill ini menjelaskan cara sederhana bagi agent AI untuk menjalankan dan men-debug kode Python dengan output error yang jelas. Skill ini ditujukan untuk orang yang menjalankan skrip Python melalui AI.

Kapan dipakai

  • ✓Saat skrip Python berhenti dan Anda tidak tahu penyebabnya.
  • ✓Saat operasi file dalam skrip gagal dan folder mungkin salah.
  • ✓Saat Anda ingin AI menampilkan isi folder untuk memastikan file berada di tempat yang seharusnya.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-execution/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Skrip saya terus gagal pada path file. Bantu saya men-debug-nya dan tunjukkan folder tempat skrip ini berjalan.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent menjalankan skrip dengan output error ditangkap dan kode keluar ditampilkan. Agent menambahkan pemeriksaan yang menampilkan direktori kerja dan daftar file di dalamnya sebelum skrip membaca atau menulis apa pun.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum

Mengapa isi folder perlu ditampilkan?

Melihat file mana yang ada sering menunjukkan mengapa sebuah file tidak bisa ditemukan.

Apakah ini hanya berlaku untuk satu jenis skrip?

Tidak. Langkah-langkahnya berlaku untuk skrip Python apa pun yang membaca atau menulis file.

Apakah saya perlu tahu Python?

Tidak perlu. Agent menangani perintahnya dan menjelaskan arti setiap output.

Detail

Deskripsi asli dari pembuat

Debug Python scripts with proper error surfacing and working directory verification

repo: HKUDS/AgentPilot

Popularitas

Bintang GitHub
7.8k
Peringkat
#12956
Lisensi
MIT
Diperbarui
1/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa