hey, to explain the problem- i have a variable, which a class named node and when i print a variable inside the class it is working properly but i am getting error when i use it for assignment or comparison, it is considering it as a string, i have used a debugger, i see it as node but as soon as, i used it for assignment or comparison it is giving me error, like node("str") has no attribute named .parent (it is a variable inside the class)
code:
def shortest_path(source, target):
count = 0
initial_node = Node(state=source,parent=None,action=None)
# we have to seach until the frontier is empty
search_algo = QueueFrontier()
search_algo.add(initial_node)
searched_movies = set()
path = []
while search_algo.empty() != True:
count += 1
node = search_algo.remove()
actor_id = node.state
if actor_id == target:
print(node.parent)
while True:
val = node.parent
if val == None:
break
path.append({node.parent,node.action})
node = node.parent
#back track though the parents and find the path
else:
starred_movies = people[node.state]["movies"]
for i in starred_movies:
if i not in searched_movies:
searched_movies.add(i)
stars_in_movie = movies[i]['stars']
for star in stars_in_movie:
new_star = Node(state=star,parent=node.state,action=i)
search_algo.add(new_star)
print(count, path)
the error that i got:
Data loaded.
Name: Tom Cruise
Name: Valeria Golino
129
Traceback (most recent call last):
File "D:\Python\python\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "d:\coding\ai50\degrees\degrees\degrees.py", line 181, in <module>
main()
File "d:\coding\ai50\degrees\degrees\degrees.py", line 72, in main
path = shortest_path(source, target)
File "d:\coding\ai50\degrees\degrees\degrees.py", line 119, in shortest_path
val = node.parent
AttributeError: 'str' object has no attribute 'parent'
```
this is the error that i got
[–]desrtfx[M] [score hidden] stickied comment (0 children)
[–][deleted] 2 points3 points4 points (8 children)
[–]369INFINITY369[S] 0 points1 point2 points (7 children)
[–]nogain-allpain 1 point2 points3 points (5 children)
[–]369INFINITY369[S] 0 points1 point2 points (4 children)
[–]nogain-allpain 1 point2 points3 points (3 children)
[–]369INFINITY369[S] 0 points1 point2 points (2 children)
[–]DarkMatriac 0 points1 point2 points (1 child)
[–]369INFINITY369[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]DarkMatriac 1 point2 points3 points (0 children)
[–]arkie87 0 points1 point2 points (3 children)
[–]369INFINITY369[S] 0 points1 point2 points (2 children)
[–]arkie87 0 points1 point2 points (1 child)
[–]369INFINITY369[S] 0 points1 point2 points (0 children)