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

Michael Torrie torriem at gmail.com
Wed Jan 27 10:49:44 EST 2021


On 1/26/21 10:19 PM, C W wrote:
> Traceback (most recent call last):
>    File "/Users/Mike/Documents/Mike/main.py", line 95, in <module>
>       main()
>    File "/Users/Mike/Documents/Mike/main.py", line 86, in main
>       args = get_feed()
>    File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed
>       result = [PERSONatabase.get_person(raw_person) for raw_neo in
> raw_objects]
>    File "/Users/Mike/Documents/Mike/main.py", line 32, in <listcomp>
>       result = [NEODatabase.get_person(raw_person) for raw_neo in
> raw_objects]
>    File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person
>       return PERSONDatabase(person['created_at'],
> KeyError: 'created_at'

The actual error is the last part, which is a KeyError on line 24.  A
key error usually is from a dictionary-like object and it means the
requested key is not found in that object.  In other words, this person
object has no "created_at" key.  Hope that makes sense.

I do not know why the code you posted refers to "employee" but the
traceback refers to "person."

In any case the trace back shows you what called what until the error
occurred. You can trace the execution of the code simply by following
it.  main() called get_feed() which set up a list comprehension, which
calls get_person() which is where the error is occurring.  I'm not
following the list comprehension stuff; I don't know why python is first
referring to PERSONatabase and then refers to NEODatabase.


More information about the Python-list mailing list