2017-10-09 2 views
0
cursor.execute("SELECT price FROM tabel WHERE id = 1600") 
print cursor.fetchone() 

에 저장 나에게pymysql 단지 선택 값과 변수

{u'price': u'4345.6'} 

어떻게 난 그냥 값 4345.6를 선택하고 약간의 수학을 할 수있는 변수에 저장할 수있는 출력을 제공?

+0

이것은 기본적인 파이썬 사전 처리입니다. 소개 문서와 튜토리얼을 읽는 것을 고려하십시오. – Parfait

답변

1

다음 코드로 쉽게 해결할 수 있습니다.

data = cursor.fetchone() #get the data in data variable 
value = float(data['price']) # load the data into value with conversion of its type