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

C W tmrsg11 at gmail.com
Tue Jan 26 22:37:30 EST 2021


Thanks for your replies. My apologies for the poor indent. I'm rewriting
the code below.

class NEODatabase:
def __init__(self, id, created_at, name, attend_date, distance):
self._id = id
self.created_at = created_at
self.name = name
self.attend_date = attend_date
self.distance = distance

@classmethod
def get_person(self, employee):
return PERSONDatabase(employee['created_at'],
employee['id'],
employee['name'],
employee['attend_date'],
employee['distance'])

I have a naive question. How do I use traceback or trace the stack? In
particular, I'm using VS Code with Python interactive console.

Say, I want to print the value of employee['name']. Can I do it? My
understanding is that these classes are just "skeletons". I must create an
instance, assign values, then test?

Thanks so much,

Mike

On Tue, Jan 26, 2021 at 9:55 PM Ed Leafe <ed at leafe.com> wrote:

> On Jan 26, 2021, at 18:16, Grant Edwards <grant.b.edwards at gmail.com>
> wrote:
> >
> >> How do you troubleshooting/debugging in Python?
> >
> > Mostly I read exception trace and read the code and think about it.
> >
> > If that doesn't work, I add some print() or syslog() calls.
> >
> > If I really get stuck, I try to write as small a program as possible
> > that demonstrates the problem.
>
> I do the first two, but if I get really stuck, I use the pudb debugger (
> https://pypi.org/project/pudb/).
>
> Using that, I can see all the locals, jump to any point in the stack and
> see the locals there, or shell into ipython if I need to run some quick
> code. For me, this is much faster than trying to write an additional
> program that is close enough to the problem code to be useful.
>
> -- Ed Leafe
>
>
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


More information about the Python-list mailing list