[Budget App] Attribute error when looping through array of objects


I am working on the budget app and am having an issue with accessing self.ledger during the custom print function.


Line 34 - 51:

  def __str__(self):
    # get the title for the output
    outputString = str(self.title)
    # subtract the title length from 30, and then divide that by two for the edges
    edge = (30-len(str(self.title)))/2
    for i in range(0,int(edge)):
      outputString = "*"+outputString
      outputString = outputString+"*"
    for obj in self.ledger:
    # grabs obj array from self.ledger
      outputDesc = obj.description if len(obj.description) <= 23 else (obj.description)[:23]
      print("Output desc")
    #   outputNum = str(obj.amount)
    #   if outputNum[0] >=7:
    #     outputNum = outputNum[:7]
    return ""

This produces a syntax error:

AttributeError: 'dict' object has no attribute 'description'

printing the obj shows the key-value pair with description, but it errors.

I’m not sure but maybe try using bracket notation .



Check this article

seems there is a better way than bracket notation also.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.