mazesolving
mazesolving copied to clipboard
Python typeerror
I don't program in Python but it seems "Node" doesn't have a method for '>' operator?
C:\Users\micha\Desktop\mazesolving-master>python solve.py -m astar perfect4k.png 4k_solve.png Loading Image Creating Maze Node Count: 2865504 Time elapsed: 32.22657132148743
Starting Solve: A-star Search
Traceback (most recent call last):
File "solve.py", line 89, in
I'm getting the same error as well. Anyone have any idea why we're experiencing this error?
I'm facing the same problem when i use Python3. Since error is not solved yet, you can temporary use Python2.
Hi. There may be some python 2 / 3 issues! I wrote this in py2, I'm also pretty much only using Python 3 now. I'm happy for suggested fixes, but ideally they'd need to work with both versions otherwise we'd simply be breaking it for others.
The issue is cause by how python 2 and 3 sort tuples of the type (int, CustomObject), in this case those tuples are (int, Maze.node). Tuples are normally sorted first by the first element then by second etc. For this work we actually only care about the sorting based on the first element anyway, if different nodes have the same weight it does not really matter which one comes first, but pythons 2 and 3 see that differently.
- Python 2: If the tuples have the same first element and the second element is object it does not try to sort by the object.
- Python 3: If the tuples have the same first element and it insist to compare the second element, which Maze.Node and it does not know how to.
Solution: Implement a comparison for Maze.Node and as we dont really care about the order it ca be as simple as:
def __lt__(self, other) -> bool:
return True
This should be added under Node class inside the Maze class.
I do not believe that this will effect the Python 2 implementation significantly.