Inexplicable error bankaccount project


I get the following error message:

Traceback (most recent call last):
File "", line 39, in
my_account = BankAccount("Hugo")
TypeError: object() takes no parameters

which refers to the following line of code:
my_account = BankAccount("Hugo")

I can't figure out what I did wrong. Anyone out there being able to support?

class BankAccount(object):
  balance = 0
  def __init___ (self, name): = name
  def __repr__ (self):
    return "%s's account. Balance: $%.2f" % (, self.balance)

  def show_balance (self):
    print "Balance: $%.2f" % (self.balance)
  def deposit (self, amount):
    if amount <= 0:
      print "Please enter a positive amount you want to deposit."
      print "You deposit $%.2f" (self.amount)
      self.balance += amount
  def withdraw (self, amount):
    if amount > self.balance:
      print "You cannot exceed your current balance."
      print "You are withdrawing $%.2f" (self.amount)
      self.balance -= amount

my_account = BankAccount("Hugo")

print my_account
my_account.deposit (2000)
my_account.withdraw (1000)
print my_account


Hi, @bleikera ,

When you instantiate an object, as follows ...

my_account = BankAccount("Hugo")

... the Python interpreter will call the __init__ method for that type of that object, if an __init__ exists for it. If the class definition for that type does not explicitly include a definition for an __init__ method, then if that class inherits from a parent class that has an __init__ method, that __init__ method is inherited, and gets called.

Check here whether you have created an __init__ method with a name that begins and ends with exactly two underscores ...

def __init___ (self, name):

If not, then your BankAccount class will not be considered by the Python interpreter as specifying its own __init__ method, and will inherit the __init__ method of object. That method does not include a name parameter, and will crash when you supply an argument within the parentheses.


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