我已经查找了类似的问题,但是在他们的案例中,问题似乎是缩进,我认为我可以接受。 这是问题所在的代码。
# -*-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
这是创建迷宫的功能:
# -*-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)
这就是Python告诉我的:
返回迷宫(机器人位置,迷宫宽度,迷宫出口,字符串) TypeError: init ()接受4个位置参数,但给出了5个
我不知道它在说的第5个论点是什么。告诉我是否需要其他解释...谢谢!