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 14:00:00 EST 2021


Hello everyone,

I'm a long time Matlab and R user working on data science. How do you
troubleshooting/debugging in Python?

I ran into this impossible situation to debug:
class person:
def __init__(self, id, created_at, name, attend_date, distance):
"""Create a new `person`.
"""
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):
"""Find and return a person by.
"""
return person(employee['created_at'],
employee['id'],
employee['name'],
employee['attend_date'],
employee['distance']
)

I got an error message saying id was 'str', but expecting 'int'.

In R, I use the interactive IDE with console. Wherever the error interrupts
the code, I just evaluate that line in the console. Very convenient!

If this error was in R, I would have tried:
> self._id = 123

But, I can't do that here! What do I do? Do I HAVE TO instantiate an object
first? It's not  convenient if I have 10 of these objects around. I need to
instantiate 10 objects.

I know hardcore computer scientists would tell me about Python debugger. R
also has one, but nobody ever uses it. I don't find them user-friendly!

Thanks a lot,

Mike


More information about the Python-list mailing list