Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
object takes no parameters
#1
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
Reply


Messages In This Thread
object takes no parameters - by amalia_jane - Feb-04-2019, 07:43 PM
RE: object takes no parameters - by buran - Feb-04-2019, 07:50 PM
RE: object takes no parameters - by amalia_jane - Feb-04-2019, 07:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  declaring object parameters with type JonWayn 2 998 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  Python Class and Object Parameters JoeDainton123 5 2,999 Sep-02-2020, 10:43 AM
Last Post: JoeDainton123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020