2014-11-12 2 views
0

이 python 파일을 실행할 때이 오류가 계속 발생합니다. 여기Float 객체가 할당시 반복 가능하지 않음

p1x, p1y = newList[0]
TypeError: 'Float' object is not iterable

를 코드입니다 : 그것은이 라인에서 발생

newList = [] 
for i, val in enumerate(poly):  
    if poly[i] != True: 
     newList.append(poly[i][0]) 
n = len(newList) 
inside =False 
p1x, p1y = newList[0] 
for i in range(n+1): 
    p2x, p2y = newList[i % n] 
    if y > min(p1y,p2y): 
     if y <= max(p1y,p2y): 
      if x <= max(p1x,p2x): 
       if p1y != p2y: 
        xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x 
       if p1x == p2x or x <= xinters: 
        return True 
    p1x,p1y = p2x,p2y 

return inside 

왜이다 내가 주변이

p1x = newList[0] 
p1y = newList[0] 

작동,하지만 다른 방법을 수행 할 때?

답변

0

newList [0]은 무엇입니까?
단일 부동 소수점 값인 경우 오류가 발생합니다.

newList [0]은 (1, 2)과 같은 튜플 이어야만합니다.

당신이 할 수있는 (newList [0] newList [1] 단일 값 경우.) :

p1x, p1y = newList[0], newList[1] 

또는

newList[0] = (1,2) 
p1x, p1y = newList[0] 
0

newList[0]Float이므로 원래 코드 시도로 두 조각으로 나눌 수 없습니다. 두 번째 시도는 과 동일한Floatp1xp1y에 할당하는 것입니다. 이는 아마도 원하는 작업이 아닙니다. 이면 p1x,p1y = newList[0], newList[0]을 쓸 수 있습니다.

관련 문제