Explanation about for

Νικόλαος Κούρας nikos.kouras at gmail.com
Tue Jan 10 06:38:36 EST 2012


On 10 Ιαν, 12:57, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-
a470-7603bd3aa... at spamschutz.glglgl.de> wrote:
> Am 10.01.2012 10:02 schrieb Νικόλαος Κούρας:
>
> > -----------------------------------------------
> > | HOST    | HITS    | AGENT     | DATE |
> > -----------------------------------------------
> > | foo     | 7       | IE6       | 1/1/11 |
> > -----------------------------------------------
> > | bar     | 42      | Firefox   | 2/2/10 |
> > -----------------------------------------------
> > | baz     | 4       | Chrome    | 3/3/09 |
> > -----------------------------------------------
>
> > In this line:
> > for host, hits, agent, date in dataset:
>
> > 'dataset' is one of the rows of the mysql result or the whole mysql
> > result set like the table above?
>
> dataset is a cursor, representing the whole result set.
>
> Iterating over it produces one row at each iteration step:
>
> for row in dataset:
>      ...
>
> As each row consists of 4 fields, one iteration result is a tuple of 4
> elements.
>
> In this case,
>
> for host, hits, agent, date in dataset:

So that means that

for host, hits, agent, date in dataset:

is:

for host, hits, agent, date in  (foo,7,IE6,1/1/11)

and then:

for host, hits, agent, date in  (bar,42,Firefox,2/2/10)

and then:

for host, hits, agent, date in  (baz,4,Chrome,3/3/09)


So 'dataset' is one row at each time?
but we said that 'dataset' represent the whole result set.
So isnt it wrong iam substituting it with one line per time only?



More information about the Python-list mailing list