When I'm running this code:
def main():
maze = []
maze_1d_arr = open(sys.argv[0], 'r')
maze_read = maze_1d_arr.readline()
maze_split = maze_read.split(" ")
size_X = int(maze_split[0])
size_Y = int(maze_split[1])
maze_grid = int(maze_split[2:])
maze = np.array(maze_grid).reshape(size_X, size_Y)
start = np.where(maze_split == 2)
end = np.where(maze_split == 3)
path = astar(maze, start, end)
print(path)
I am getting this error;
size_X = int(maze_split[0])
ValueError: invalid literal for int() with base 10: 'import'
Is there any way this can be fixed? It is coming from a text file which has this one line:
6 4 0 0 1 0 0 0 2 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0 3 0
As a bit of background on the file, the first number is supposed to represent the x axis, the second number is supposed to represent the y axis and the third number onwards is the grid.
Many thanks :)
EDIT:
I have changed the code to this:
def main():
maze = []
maze_1d_arr = open(sys.argv[1], 'r')
maze_read = maze_1d_arr.readline()
maze_split = maze_read.split(" ")
size_X = [int (X) for X in maze_split[0]]
size_Y = [int (Y) for Y in maze_split[1]]
maze_grid = [int (x) for x in maze_split[2:]]
maze = np.array(maze_grid).reshape(size_X, size_Y)
start = np.where(maze_split == 2)
end = np.where(maze_split == 3)
path = astar(maze, start, end)
print(path)
But I'm now getting this error,
size_Y = [int (Y) for Y in maze_split[1]]
IndexError: list index out of range
I am still using the same file as before for the code, any ideas on how to fix this?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…