[英]It seems i can't use a function inside another function
I'm trying to build a little short path problem I succesfully created the nodes as objects, defined the starting one and the final one with dedicated functions and computed(with a dedicated function) the neighbors inside a radius for any given node using an euclidean distance(dedicated function as well)我正在尝试构建一个小短路径问题我成功地将节点创建为对象,使用专用函数定义了起始节点和最后一个节点,并使用欧几里德计算(使用专用函数)任何给定节点的半径内的邻居距离(还有专用功能)
I'm sure the neighbors function, where nodes is a list nodes and node is the node of which i want to compute the neighboring nodes, works.我确定邻居函数,其中节点是一个列表节点,节点是我想要计算相邻节点的节点,工作。
def neighbors(nodes,node):
neighbors=[]
for i in nodes:
dist=distance(i,node)
if dist<=15:
neighbors.append(i)
return neighbors
when i try and call the function to select a path from the starting node to the final node当我尝试调用该函数来选择从起始节点到最终节点的路径时
def choose_path(final_node,starting_node,nodes):
neighbors=neighbors(nodes,starting_node)
more code
after i defined nodes and starting node, it raises an error: "local variable 'neighbors' referenced before assignment" and i can't understand why.在我定义节点和起始节点后,它引发了一个错误:“在赋值之前引用了局部变量‘邻居’”,我不明白为什么。 Am I doing something wrong?难道我做错了什么?
Thank you in advance to those who will help me!在此先感谢那些愿意帮助我的人!
You are trying to call neighbors()
and then assign the result to neighbors
.您正在尝试调用neighbors()
,然后将结果分配给neighbors
。
Don't use the same name for your variable as your function.不要为您的变量使用与您的函数相同的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.