Budget app problem with transfer method


Any tips would be most helpful.

I’ve been wrangling with this problem for awhile, I continue to get the error shown below my code. I’ve tried using category.name, category, etc. but nothing eliminates the “attribute error” on line 29 in the transfer method. I’m able to withdraw find, but not deposit.


class Category:

    def __init__(self, name):
        self.name = name
        self.ledger = []

    def __str__(self):
        return str(self.name)

    def deposit(self, amount, description=''):
        self.ledger.append({"amount": amount, "description": description.__str__()})

    def get_balance(self):
        self.balance = 0
        for item in self.ledger:
            self.balance += item["amount"]
        return self.balance

    def withdraw(self, amount, description=''):
        if self.check_funds(amount) is True:
            return self.ledger.append({"amount": (amount *- 1), "description": description.__str__()})
            return False

    def transfer(self, amount, category):
        tf_desc = str("Transfer from " + str(self))
        tt_desc = str("Transfer to " + category.__str__())
        self.withdraw(amount, str(tf_desc))
        category.name.deposit(amount, tt_desc.__str__())

    def check_funds(self, amount):
        self.balance = 0
        for item in self.ledger:
            self.balance += item["amount"]
        if self.balance < abs(amount):
            return False
            return True

def create_spend_chart(*args):

Traceback (most recent call last):
File “main.py”, line 12, in
food.transfer(50, clothing)
File “/home/runner/boilerplate-budget-app-1/budget.py”, line 29, in transfer
category.name.deposit(amount, tt_desc.str())
AttributeError: ‘str’ object has no attribute ‘deposit’
exit status 1```

Remember that name is just one of the the attributes defined in the __init__. The actual instance of the object that’s passed in to the transfer function is the category.

1 Like

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