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

Cameron Simpson cs at cskk.id.au
Wed Jan 27 00:55:08 EST 2021


On 27Jan2021 00:19, C W <tmrsg11 at gmail.com> wrote:
>Here's the code again, class should be called PERSONDatabase, 
>misspelled
>earlier:
>class PERSONDatabase:
>   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

Here's you're setting attributes (which is a very normal thing to do).

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

I think this "employee" is called "person" in the code the traceback 
came from. It is better when these two things match.

>The PERSONDatabase class is called from main. This is the trace back I got
>from the VS code:
>
>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'

Here's you're trying to index another object using a string, which seems 
to resemble the .created_at attribute in your PERSONDatabase object.

I would presume from this that the "person" object at the bottom of the 
traceback is the "raw_person" called above it. But I do not see 
raw_person defined anywhere. Are you sure you didn't mean to pass 
"raw_neo" instead of "raw_person"? That would be more normal, since 
you're iterating over "raw_objects".

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list