Skip to content

Instantly share code, notes, and snippets.

@sammlapp
Created April 10, 2025 13:49
Show Gist options
  • Save sammlapp/7fba81201dd55f569fed940dc1b308d4 to your computer and use it in GitHub Desktop.
Save sammlapp/7fba81201dd55f569fed940dc1b308d4 to your computer and use it in GitHub Desktop.
Debugging in Python - lab meeting

how to debug, and how to ask for help debugging

warnings vs errors: know the difference

breakpoints: interactive debugging in VS Code

print everything out: check intermediate values

reading error messages carefully

read the docstring or documentation of functions/classes/packages used

asking for help:

describe what you are doing

provide the full error message

if possible, provide a self-contained example that reproduces the error

opening an issue:

if you find a bug in opensoundscape, open an issue

the issue should describe what code in opso is causing the issue

provide the example that reproduces the issue

if you think you know a solution, provide it in the issue

issues can also be feature requests; discussions or questions can go in forums or in slack

avoiding bugs in your code:

write comments to yourself/others

use descriptive variable names and don't use keywords

avoid repeated code (use loops and functions instead)

read docstrings!!!!

smoke tests

perform a code snippet with a known dataset, and make sure it works like you expect it to

Reproducibility

save a copy of your script alongside the outputs, in case you modify the original script

also save the enviornment exported to a yml file with conda env export -f my_env.yml

write detailed comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment