python-debug-pattern
यह क्या करती है
यह स्किल AI एजेंट को Python स्क्रिप्ट चलाने और यह पता लगाने का दोहराया जा सकने वाला तरीका देती है कि वे क्यों विफल होती हैं। यह उन सभी के लिए है जिन्हें स्क्रिप्ट से साफ़ एरर विवरण चाहिए।
कब इस्तेमाल करें
- ✓जब Python स्क्रिप्ट विफल हो और आपको सिर्फ़ एक अस्पष्ट संदेश दिखे।
- ✓जब स्क्रिप्ट फ़ाइल में लिखती हो और आपको पक्का करना हो कि वह कहाँ गई।
- ✓जब आप चाहें कि AI एक अच्छे रन की तुलना एक खराब रन से करे।
Skill का लिंक
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-pattern/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरी process_data स्क्रिप्ट चलाइए और बताइए कि वह ठीक-ठीक क्यों विफल होती है, पूरी एरर सहित।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट stderr पकड़कर स्क्रिप्ट चलाता है और exit code छापता है। वह कार्य-फ़ोल्डर और उस फ़ाइल का पूरा पाथ दर्ज करता है जिसमें स्क्रिप्ट लिखती है।
तकनीकी सामग्री (मूल 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>&1redirects 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 |
अक्सर पूछे जाने वाले सवाल
traceback क्या है?
traceback वे चरण हैं जो 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
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
agentpilot
7.8kआपके एजेंट को AgentPilot से प्रोजेक्ट को चरण-दर-चरण सुधारने में मदद करती है, जिसमें बदलाव सुझाए, परखे और स्कोर किए जाते हैं।
openspace
7.8kआपके एजेंट को OpenSpace सेट करने में मदद करती है, जो एजेंट स्किल्स सहेजता और वापस लाता है, और MCP के ज़रिए आपके AI ऐप से जुड़ता है।
rsi-arena
7.8kआपके एजेंट को AIME और Terminal-Bench जैसे मानक AI बेंचमार्क टेस्ट सेट करने और चलाने में मदद करती है, ताकि सुधार के तरीकों की तुलना हो सके।
experiment-guide
7.8kआपके एजेंट को छोटे प्रयोग बनाने, उनके नतीजे पढ़ने और जाँच के दौरान उपयोगी निष्कर्ष लिखने में मदद करती है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।