- Notifications
You must be signed in to change notification settings - Fork 0
python_general
Marcel Schmalzl edited this page Feb 19, 2025 · 4 revisions
python -m pdb main.py export PYTHONBREAKPOINT=pdb.set_trace python main.pyimport sys, pdb; sys.excepthook = lambda exctype, value, tb: (print("Unhandled exception detected. Entering debugger..."), pdb.post_mortem(tb))breakpoint()To be used within a debug prompt.
# Continue exec until next breakpoint continue # Step over (exec line but don't step into func) next # Step into (enter func & stop at 1st line inside it) step # Return from current func returnbreak relative/path/to/script.py:10Note that you cannot break at comments / empty lines / ...
break my_funcbreak relative/path/to/script.py:10, x > 5disable # same as: disable 1 # disable all disable allYou need to continue if you don't want to stay in the current break.
Print the structure of a whole object via pprint.pprint(vars(...)):
import pprint # Object to inspect class PhysicalFunction: def __init__(self): self.name = "ExampleFunction" self.parameters = { "param1": 10, "param2": 20, "param3": [1, 2, 3, 4, 5], "param4": {"subparam1": "value1", "subparam2": "value2"} } self.description = ("This is a detailed description of the ExampleFunction. " "It includes multiple parameters and nested structures.") attributes = pprint.pprint(vars(PhysicalFunction()))Output:
{'description': 'This is a detailed description of the ExampleFunction. It ' 'includes multiple parameters and nested structures.', 'name': 'ExampleFunction', 'parameters': {'param1': 10, 'param2': 20, 'param3': [1, 2, 3, 4, 5], 'param4': {'subparam1': 'value1', 'subparam2': 'value2'}}}
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License *.
Code (snippets) are licensed under a MIT License *.
* Unless stated otherwise