# Python 当在类中写递归函数的时候出现AttributeError: 'Solution' object has no attribute 'hepler'，但是明明类中有这个函数

``````
import math

import pandas as pd
class Point:
def __init__(self,id,x,y,z,type):
self.id=id
self.x=x
self.y=y
self.z=z
self.type=type  #为1是垂直校正点，为0是水平校正点
self.visited=False
return
def __str__(self):
return ("id: {}; x: {}; y: {}; z: {}; type: {}; visited: {}".format(self.id, self.x, self.y,self.z,self.type,self.visited))

class Solution:
def __init__(self):
self.point=[]
self.path=[]
self.pointA=None
self.pointB=None
self.curr = self.pointA
self.pvv=25
self.pvh=15
self.phv=20
self.phh=25
self.p5=30
self.pa=0.001
self.path.append(self.pointA)

def distance(self,a,b):
return math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z))

def check(self,target,b,v,h):
err_v=v+self.distance(target,b)*self.pa
err_h=h+self.distance(target,b)*self.pa
if target.type == 1:  # 垂直校正点
if err_v <= self.pvv and err_h <= self.pvh:
return True
else:  # 水平校正点
if err_v <= self.phv and err_h <= self.phh:
return True
return False

def init(self):
row=data1.shape[0]
for i in range(row):
if(data1.iloc[i,4] =="A 点"):
self.pointA=Point(data1.iloc[i,0],data1.iloc[i,1],data1.iloc[i,2],data1.iloc[i,3],data1.iloc[i,4])
continue
if (data1.iloc[i, 4] == "B点"):
self.pointB = Point(data1.iloc[i, 0], data1.iloc[i, 1], data1.iloc[i, 2], data1.iloc[i, 3], data1.iloc[i, 4])
continue
temp=Point(data1.iloc[i,0],data1.iloc[i,1],data1.iloc[i,2],data1.iloc[i,3],data1.iloc[i,4])
self.point.append(temp)

def start(self):
target=self.pointA
pre_v=0
pre_h=0
self.helper(target, self.pointB, pre_v,pre_h)
for i in s.path:
print(i)

def helper(self,target,aim,pre_v,pre_h):
if self.check(target,self.pointB,pre_v,pre_h)==True:
return True
potential=[]
for temp in self.point:
if temp.visited == False:
d = self.distance(temp,target)
err_v = pre_v + d * self.pa
err_h = pre_h + d * self.pa
if temp.type==1: # 垂直校正点
if (err_v<=self.pvv) and (err_h<=self.pvh):
potential.append(temp)
else:#水平校正点
if (err_v<=self.phv) and (err_h<=self.phh):
potential.append(temp)
if len(potential)==0:
return False
for test in potential:
target1=test
self.point.remove(target1)
target1.visited=True
self.path.append(target1)
if target1.type==1:
pre_v=0
pre_h=err_h
if not self.hepler(target1, aim, pre_v, pre_h):
self.point.append(target1)
target1.visited = False
self.path.remove(target1)
else:
pre_v=err_v
pre_h=0
if not self.hepler(self,target1, aim, pre_v, pre_h):
self.point.append(target1)
target1.visited = False
self.path.remove(target1)

s=Solution()
s.init()
s.start()

``````

Traceback (most recent call last):
if not self.hepler(self,target1, aim, pre_v, pre_h):
AttributeError: 'Solution' object has no attribute 'hepler'

• 写回答

• 已结题 8月22日
• 已采纳回答 8月22日
• 创建了问题 8月22日

#### 悬赏问题

• ¥15 如何判断一个数是否为超级素数