2013-09-16 1 views
0

커서 실행 SELECT가 변수 "s"와 일치하지만 "for"루프는 "s"를 사용하여 작동하지 않습니다 (아무 것도 인쇄되지 않습니다). 그러나 , 커서와 함께 작동하여 SELECT를 직접 실행합니다. 문제가 무엇입니까? "s"가 커서와 같은 객체가 SELECT를 실행하지 않습니까?sqlite 파이썬에서 변수를 사용할 때 루프가 인쇄되지 않습니다

>>>import sqlite3 
>>>con=sqlite3.connect('prueba.db') 
>>>cur=con.cursor() 
>>>cur.execute('''CREATE TABLE tabla1(ExtremoA text,ExtremoZ text,PotenciaRxA real,PotenciaTxA real,PotenciaRxZ real,PotenciaTxZ real,SpanLossAZ real,SpanLossZA real)''') 
print "Tabla1 creada exitosamente" 
>>>registros=[('Quillota','San felipe',-9,4,-11,3,15,12),('San Felipe','Las Cuevas',-10,2,-12,6,16,14)] 
>>>sql='''INSERT INTO tabla1(ExtremoA,ExtremoZ,PotenciaRxA,PotenciaTxA,PotenciaRxZ,PotenciaTxZ,SpanLossAZ,SpanLossZA)VALUES(?,?,?,?,?,?,?,?)''' 
>>>cur.executemany(sql,registros) 
>>>con.commit() 
>>>print "registros creados exitosamente" 
>>>s=cur.execute('''SELECT * FROM tabla1''') 
>>>todo=cur.fetchall() 
>>>print todo 
>>>for i in s: 
    print i 
>>>cur.close() 
>>>con.close() 

답변

1

todo=cur.fetchall()에서 이미 todo에 행을 검색했습니다 그래서 거기에 아무것도 어쨌든 반복하는 남아 있지 :

프로그래밍 루틴은 다음입니다. 따라서 s 대신 todo을 반복하면됩니다. 그렇지 않으면 그 라인을 없애고 cur ...

+0

을 얻으십시오. 일부 개념은 분명하지 않습니다. 그게 다 괜찮아. –

관련 문제