with one click
python-debug-execution
Debug Python scripts with proper error surfacing and working directory verification
Menu
Debug Python scripts with proper error surfacing and working directory verification
Delegate tasks to OpenSpace — a full-stack autonomous worker for coding, DevOps, web research, and desktop automation, backed by an extensive MCP tool and skill library. Skills auto-improve through use, reducing token consumption over time. A cloud community lets agents share and collectively evolve reusable skills.
Incremental audio production with duration mismatch handling, adaptive stem extension, and pre-mix alignment verification
Audio production with diagnostic analysis, timecode parsing from documents, and verified export workflow
Incremental audio production with duration alignment handling, per-stem verification, and adaptive extension strategies
Step-by-step audio production with per-stem verification, timing alignment, and incremental quality gates
End-to-end audio production workflow with stems, effects, archiving, and verification
| name | python-debug-execution |
| description | Debug Python scripts with proper error surfacing and working directory verification |
When executing Python scripts that may fail, use this pattern to surface clear error information and diagnose issues effectively.
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 visibleecho Exit code: $? reveals the actual exit status for debuggingBefore 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:
#!/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()
python3 script.py 2>&1 ; echo Exit code: $?
Look for:
| 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 |