Explanation about for

Νικόλαος Κούρας nikos.kouras at gmail.com
Mon Jan 9 18:23:22 EST 2012


================================
dataset = cursor.fetchall()

for row in dataset:
    print ( "<tr>" )

    for item in row:
        print ( "<td><b><font color=yellow> %s </td>" % item )
================================

and this:

================================
dataset = cursor.fetchall()

for host, hits, agent, date in dataset:
    print ( "<tr>" )

    for item in host, hits, agent, date:
        print ( "<td><b><font color=white> %s </td>" % item )
================================


Can you please explain me how the for structure works here?

a) In the 1st example we have 'for row in dataset' what is the value
of 'row' at that time? What part of 'dataset' is 'row'?

b) In the 2nd example we have for 'host, hits, agent, date in
dataset'. How does these 4 variables take their values out of dataset?
How dataset is being splitted?


Please explain to me if you like as simple as you can
Thank you.



More information about the Python-list mailing list