Skillpedia
برمجة عامة7.8k · #12956

python-debug-execution

ما الذي تفعله

تشرح هذه المهارة طريقة بسيطة لوكيل الذكاء الاصطناعي لتشغيل شيفرة Python وتصحيحها مع مخرجات خطأ واضحة. وهي مناسبة لمن يشغّل سكربتات Python عبر الذكاء الاصطناعي.

متى تستخدمها

  • ✓عندما يتوقف سكربت Python ولا أعرف السبب.
  • ✓عندما تفشل عمليات الملفات داخل السكربت وقد يكون المجلد خاطئًا.
  • ✓عندما أريد من الذكاء الاصطناعي أن يعرض محتويات المجلد للتأكد من وجود الملفات في أماكنها.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-execution/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“سكربتي يفشل باستمرار عند مسار ملف. ساعدني في تصحيحه، وأرني المجلد الذي يعمل فيه.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يشغّل الوكيل السكربت مع التقاط مخرجات الخطأ وطباعة رمز الخروج. ويضيف فحوصًا تطبع مجلد العمل ومحتوياته قبل أن يقرأ السكربت أو يكتب أي شيء.

المحتوى التقني (ملف 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
آخر تحديث
1‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة