Python Forum
object takes no parameters - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: object takes no parameters (/thread-15874.html)



object takes no parameters - amalia_jane - Feb-04-2019

Hello!! So I'm pretty new to python, and am trying to learn via a course, but there is no forum for it so I thought I would try my luck here.

I'm attempting to import a module from a relative path, but am getting an error that says my object takes no parameters. I'm pretty sure I've followed this work exactly, but something is tripping me up. If I could get a second pair of eyes on this, it would be super helpful!

Context:
class file contains this (in folder called "classes"
class Enemy:
    def ___init___(self, hp, mp):
        self.max_hp = hp
        self.hp = hp
        self.max_mp = mp
        self.mp = mp

    def get_hp(self):
        return self.hp
Attempt to import into main file looks like this:
from classes.enemy import Enemy


enemy = Enemy(200, 60)
print(enemy.get_hp())
Error:
Traceback (most recent call last):
  File "/Users/amaliad/PycharmProjects/Attack/attack.py", line 9, in <module>
    enemy = Enemy(200, 60)
TypeError: object() takes no parameters



RE: object takes no parameters - buran - Feb-04-2019

__init__() is with 2 underscores on both sides. You have 3 underscores on each side ___init___().


RE: object takes no parameters - amalia_jane - Feb-04-2019

Oh my goodness, thank you so much! I feel so silly. Still getting used to the formatting colors, should have realized something was off!