Print-Debugging funktioniert, ist aber langsam. Breakpoints, Step-Through, Profiling — professionelle Werkzeuge für professionelles Debugging.
breakpoint() — eingebauter Debugger¶
def process_data(items): for item in items: result = transform(item) breakpoint() # Hält hier an — pdb-Prompt save(result)
pdb-Befehle: n(ext), s(tep), c(ontinue), p(rint) var, l(ist), q(uit)¶
VS Code Debugging¶
// .vscode/launch.json { “configurations”: [{ “name”: “Python: Current File”, “type”: “debugpy”, “request”: “launch”, “program”: “${file}”, “console”: “integratedTerminal” }] }
Profiling¶
cProfile¶
python -m cProfile -s cumulative myapp.py
line_profiler¶
@profile def slow_function(): …
kernprof -l -v myapp.py¶
Wichtigste Erkenntnis¶
breakpoint() für schnelles Debugging, VS Code für Step-Through, cProfile für Performance. Hören Sie auf, print() zu verwenden.