Skip to content

Latest commit

 

History

History
53 lines (42 loc) · 1.36 KB

File metadata and controls

53 lines (42 loc) · 1.36 KB

Python Bytecode Inspector

Python Bytecode Inspector

This tool compiles Python files to bytecode and allows inspection of the generated bytecode.

Implementation

# bytecode_inspector.py code here...

Usage Examples

Compile and inspect closures.py

python bytecode_inspector.py closures.py

Inspect existing bytecode without recompiling

python bytecode_inspector.py closures.py --no-compile

Batch process multiple files

for file in *.py; do
  echo "Processing $file..."
  python bytecode_inspector.py "$file"
done

Mermaid Diagram: Bytecode Inspection Process

flowchart TD
    A[Python Source File] -->|py_compile| B[.pyc File]
    B -->|importlib| C[Load Module]
    B -->|direct read| D[Read Raw Bytecode]
    C -->|dis.dis| E[Disassemble Functions]
    D -->|marshal.load| F[Load Code Object]
    F -->|dis.dis| G[Disassemble Raw Bytecode]
    E --> H[Bytecode Analysis]
    G --> H
Loading

Future Enhancements

  • Add comparison between different Python versions
  • Visualize bytecode execution flow
  • Analyze optimization opportunities