반응형
이상한 문제가 있습니다. 부울을 반환하는 메서드가 있습니다. 차례로 프런트 엔드에서 메서드를 직접 호출 할 수 없으므로 해당 함수의 결과가 다시 반환되어야합니다. 내 코드는 다음과 같습니다.
# this uses bottle py framework and should return a value to the html front-end
@get('/create/additive/<name>')
def createAdditive(name):
return pump.createAdditive(name)
def createAdditive(self, name):
additiveInsertQuery = """ INSERT INTO additives
SET name = '""" + name + """'"""
try:
self.cursor.execute(additiveInsertQuery)
self.db.commit()
return True
except:
self.db.rollback()
return False
예외가 발생합니다. TypeError ( " 'bool'object is not iterable",)
bool 값을 "반복"하지 않고 반환하려고하기 때문에이 오류가 전혀 발생하지 않습니다.
부울이나 int 대신 문자열을 반환하면 예상대로 작동합니다. 여기서 문제가 될 수 있습니까?
추적 :
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\bottle.py", line 821, in _cast
out = iter(out)
TypeError: 'bool' object is not iterable
해결 방법
역 추적을보십시오.
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\bottle.py", line 821, in _cast
out = iter(out)
TypeError: 'bool' object is not iterable
코드가 값을 반복하는 것이 아니라 수신하는 코드입니다.
해결책은 이터 러블 반환입니다. bool을 문자열 ( str (False)
)로 변환하거나 튜플 ( (False,)
)로 묶는 것이 좋습니다.
항상 역 추적을 읽으십시오. 정확하고 도움이됩니다.
참조 페이지 https://stackoverflow.com/questions/17630323
반응형
'파이썬' 카테고리의 다른 글
파이썬 What's the fastest way in Python to calculate cosine similarity given sparse matrix data? (0) | 2021.01.13 |
---|---|
파이썬 int 값을 유니 코드로 변환 (0) | 2021.01.13 |
파이썬 이미지에서 텍스트 인식을위한 간단한 파이썬 라이브러리 (0) | 2021.01.13 |
파이썬 삼중 큰 따옴표 vs. 큰 따옴표 (0) | 2021.01.13 |
파이썬 Pandas를 사용하여 시간별 / 분별 시간 범위 만들기 (0) | 2021.01.13 |
댓글