1

I have looked up similar questions, but in their cases, the problem seems to be the indent, which I think I'm ok with. This is the code where the problem is.

# -*-coding:Utf-8 -*

"""This module contains the class "Labyrinth" """

class Labyrinth:

    def __init__(self, robot_position, width, exit, string):
        self.robot_position = robot_position
        self.width = width
        self.string = string
        self.exit = exit

    def __str__(self):
        return self.string

This is the function creating the labyrinth:

# -*-coding:Utf-8 -*

""" This module contains the function "create_labyrinth_from_string" """

from classes.labyrinth import *

def create_labyrinth_from_string(string):
    #We look where is the robot
    i = 0
    for symbol in string:
        if symbol == 'X':
            robot_position = i
        else:
            i += 1
    #We calculate the labyrinth's width
    i = 0
    for symbol in string:
        if symbol == '\n':
        labyrinth_width = i
        else:
            i += 1

    #We look where is the labyrinth's exit
    i = 0
    for symbol in string:
        if symbol == 'U':
            labyrinth_exit = i
        else:
            i += 1

    #We create and return the labyrinth
    return Labyrinth(robot_position, labyrinth_width, labyrinth_exit, chaine)

And this is what Python tells me:

return Labyrinth(robot_position, labyrinth_width, labyrinth_exit, string) TypeError: init() takes 4 positional arguments but 5 were given

I don't know what is the 5th argument it's talking about. Tell me if you need any other explanation... Thank you!

Vincent Quirion
  • 389
  • 2
  • 4
  • 16
  • 3
    Do you have folder "\_\_pycache__" in the current working directory? If so, delete it and try running your code again. – DYZ Aug 03 '18 at 00:20
  • It worked thank you. Could you explain me why it did? – Vincent Quirion Aug 03 '18 at 00:22
  • You probably had an earlier version of the class where `__init__` had only four parameters. That version got cached. – DYZ Aug 03 '18 at 00:23
  • [This](https://stackoverflow.com/questions/16869024/what-is-pycache) may be useful. – DYZ Aug 03 '18 at 00:24

0 Answers0