How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

Grant Edwards grant.b.edwards at gmail.com
Tue Jan 26 22:30:27 EST 2021


On 2021-01-27, Cameron Simpson <cs at cskk.id.au> wrote:

> Me either. Like grant, i fall into the "look at the stack trace and 
> think a bit, then put in print() calls or similar to show me whether 
> things are what I expect them to be when the code runs".
>
> I actually have a Computer Science degree, but I think there are 
> definition those who like debuggers and those who tend not to.

Me too (MS in CSci), but I can't remember the last time I used a
debugger. It may help that I "grow" my apps. I don't sit down, write a
3000 line program, and then try to debug the program. That just
doesn't work. It doesn't matter how much UML you can point to if a
couple of your basic assumptions turned out to be wrong.

Write small funtions, and add small chunks of code, and test as you go
to make sure things work the way you thought they were going to. If it
used to work, you've only added 5 lines of code, and now it doesn't
work, it's usually not hard to figure out what's wrong.

And don't be afraid to refactor stuff when your original approach
starts to smell -- if you just keep going it will only get worse.

Source control can also be a lifesaver if you get really confused.

--
Grant





More information about the Python-list mailing list