Link to home
Start Free TrialLog in
Avatar of cpeters5
cpeters5

asked on

Python loop example

I need an example of python code that does the following

execute the query "select id, col1, col2 from tab1"
Then Iterate through the query results
 
Thanks
Avatar of plusone3055
plusone3055
Flag of United States of America image

c.execute(select id, col1, col2 from tab1)
print c.fetchall()


or 


c.execute(select id, col1, col2 from tab1)
for i in range(c.rowcount): 
row = c.fetchall()
print row

Open in new window

Avatar of cpeters5
cpeters5

ASKER

Thanks plusone3055
Would you please expand a little?  Within th eloop, I want to do one thing with col1 and another with col2.
I want to see explicit syntax for getting individual elements off row.
say, printing col1 and col2 in two separate print statements.

Sorry, a newbie.
Thanks
ASKER CERTIFIED SOLUTION
Avatar of gelonida
gelonida
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial