Explanation about for

Discussion in 'Python' started by Íéêüëáïò Êïýñáò, Jan 9, 2012.

  1. ================================
    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.
     
    Íéêüëáïò Êïýñáò, Jan 9, 2012
    #1
    1. Advertising

  2. Íéêüëáïò Êïýñáò

    Ian Kelly Guest

    2012/1/9 Íéêüëáïò Êïýñáò <>:
    > ================================
    > 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?


    You should probably read through the Python tutorial or a Python book
    for the basics of Python for loops.

    > 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'?


    dataset is an iterable object, which means that Python can ask it for
    an iterator and then use that iterator to "loop" through the dataset
    in some fashion. In this case, 'dataset' is a database cursor, and
    the values returned by the iterator are the rows that were selected by
    the query that executed, represented as tuples. 'row' takes on the
    value of each of those tuples, one at a time.

    > 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?


    The second example works the same way as the first, except that
    instead of storing each row tuple in a single variable called row, it
    unpacks each tuple into four different variables named 'host', 'hits',
    'agent', and 'date'. These represent the values of the selected
    columns from the query, for each selected row.

    HTH,
    Ian
     
    Ian Kelly, Jan 9, 2012
    #2
    1. Advertising

  3. Íéêüëáïò Êïýñáò

    Chris Rebert Guest

    On Mon, Jan 9, 2012 at 3:23 PM, Îικόλαος ΚοÏÏας <> wrote:
    > ================================
    > dataset = cursor.fetchall()
    >
    > for row in dataset:
    >    print ( "<tr>" )
    >
    >    for item in row:
    >        print ( "<td><b><font color=yellow> %s </td>" % item )
    > ================================
    >
    > and this:
    >


    Your second snippet makes use of Python's
    iterable/sequence/tuple-unpacking feature. Here's the relevant part of
    the Language Reference:
    http://docs.python.org/reference/simple_stmts.html#assignment-statements

    By way of example, given:
    seq = [1,2,3,4]
    Then:
    w, x, y, z = seq
    Results in:
    w = 1
    x = 2
    y = 3
    z = 4
    `seq` has been "unpacked", and its elements have been assigned to
    variables (namely: `w`, `x`, `y`, and `z`). If the number of variables
    doesn't match the number of elements, Python will raise an exception.

    > ================================
    > dataset = cursor.fetchall()
    >
    > for host, hits, agent, date in dataset:


    for-loops perform repeated assignments to the loop variable(s), and,
    like with the simple assignment statement example I gave, also permit
    the use of unpacking in such assignments. To make the unpacking more
    explicit, the loop can be equivalently rewritten as:
    for _row in dataset:
    host, hits, agent, date = _row
    # rest same as before...

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


    Python's syntax for tuples is based solely on commas and does not
    require parentheses, though a tuple's repr() always includes the
    parentheses and programmers often/typically do too. (See
    http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences
    ..) For example:
    x = 1, 2
    And:
    x = (1, 2)
    Both do exactly the same thing: set `x` to a tuple of length 2
    containing the elements 1 and 2.
    The loop thus might be more clearly written as:
    for item in (host, hits, agent, date):
    So, what's happening is that Python is iterating over the elements of
    an anonymous literal tuple; `item` will thus take on the values of
    `host`, `hits`, `agent`, and `date`, in turn.

    >        print ( "<td><b><font color=white> %s </td>"% item )
    > ================================


    Cheers,
    Chris
    --
    http://rebertia.com
     
    Chris Rebert, Jan 9, 2012
    #3
  4. Íéêüëáïò Êïýñáò

    Ian Kelly Guest

    2012/1/9 Íéêüëáïò Êïýñáò <>:
    > if the MySQL query was:
    >
    > cursor.execute( '''SELECT host, hits, agent, date FROM visitors WHERE pin=
    > %s ORDER BY date DESC''', pin )
    >
    > can you help me imagine how the mysql database cursor that holds the query
    > results would look like? I must somehow visualize it in order to understand
    > it!


    You can think of it as a pointer, traversing over one row of the
    result set at a time. Hopefully this will come out legibly:

    -----------------------------------------------
    | HOST | HITS | AGENT | DATE |
    ----------------------------------------------- -------------
    | foo | 7 | IE6 | 1/1/11 | <---- | cursor |
    ----------------------------------------------- -------------
    | bar | 42 | Firefox | 2/2/10 |
    -----------------------------------------------
    | baz | 4 | Chrome | 3/3/09 |
    ------------------------------------------------


    > Also what happend if the query was:
    > cursor.execute( '''SELECT host FROM visitors") ?
    >
    > the result would have to be something likelike?
    >
    > -----------------
    > |somehost1|
    > -----------------
    > |somehost2|
    > -----------------
    > |somehost3|
    > -----------------
    > .....................
    > .....................
    > |somehost n|
    > -----------------
    >
    > So what values host, hits, agent, date would have in 'for host, hits,agent,
    > date in
    >  dataset' ? Every row has one string how can that be split in 4?


    Why don't you try it and see what happens? But to spare you the
    suspense, you would get:

    ValueError: need more than 1 value to unpack

    Because you can't unpack a 1-length tuple into four variables. The
    code assumes that the query is selecting exactly 4 columns.
     
    Ian Kelly, Jan 10, 2012
    #4
  5. On 10 Ιαν, 03:11, Ian Kelly <> wrote:
    > 2012/1/9 Ãéêüëáïò Êïýñáò <>:
    >
    > > if the MySQL query was:

    >
    > > cursor.execute( '''SELECT host, hits, agent, date FROM visitors WHERE pin =
    > > %s ORDER BY date DESC''', pin )

    >
    > > can you help me imagine how the mysql database cursor that holds the query
    > > results would look like? I must somehow visualize it in order to understand
    > > it!

    >
    > You can think of it as a pointer, traversing over one row of the
    > result set at a time.  Hopefully this will come out legibly:
    >
    > -----------------------------------------------
    > | HOST | HITS | AGENT | DATE |
    > -----------------------------------------------            -------------
    > | foo     | 7       | IE6       |1/1/11 |   <----   | cursor |
    > -----------------------------------------------            -------------
    > | bar     | 42     | Firefox  | 2/2/10 |
    > -----------------------------------------------
    > | baz    | 4       | Chrome | 3/3/09 |
    > ------------------------------------------------


    Database cursor is the pointer that iterates over the result set one
    row at a time?
    I though that it was the name we give to the whole mysql result set
    returned my cursor.execute.

    >
    >
    > > Also what happend if the query was:
    > > cursor.execute( '''SELECT host FROM visitors") ?

    >
    > > the result would have to be something likelike?

    >
    > > -----------------
    > > |somehost1|
    > > -----------------
    > > |somehost2|
    > > -----------------
    > > |somehost3|
    > > -----------------
    > > .....................
    > > .....................
    > > |somehost n|
    > > -----------------

    >
    > > So what values host, hits, agent, date would have in 'for host, hits, agent,
    > > date in
    > >  dataset' ? Every row has one string how can that be split in 4?

    >
    > Why don't you try it and see what happens?  But to spare you the
    > suspense, you would get:
    >
    > ValueError: need more than 1 value to unpack
    >
    > Because you can't unpack a 1-length tuple into four variables.  The
    > code assumes that the query is selecting exactly 4 columns.



    -----------------------------------------------
    | 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?

    I still have trouble understanding this line :(
     
    Íéêüëáïò Êïýñáò, Jan 10, 2012
    #5
  6. 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:

    is shorthand for

    for anyunusedvariablename in dataset: # take complete row
    host, hits, agent, date = anyunusedvariablename # tuple unpacking
    del anyunusedvariablename # remove traces

    exept that the said variable isn't created.


    Thomas
     
    Thomas Rachel, Jan 10, 2012
    #6
  7. On 10 Ιαν, 12:57, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-
    > 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?
     
    Îικόλαος ΚοÏÏας, Jan 10, 2012
    #7
  8. On 10 Ιαν, 12:57, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-
    > 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?
     
    Îικόλαος ΚοÏÏας, Jan 10, 2012
    #8
  9. Îικόλαος ΚοÏÏας writes:

    > 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?


    Forget the database and meditate on simpler examples like this:

    >>> xy = zip("abc", "123")
    >>> for x, y in xy: print(x, y)

    ....
    ('a', '1')
    ('b', '2')
    ('c', '3')
    >>> for x, y in xy: print(xy)

    ....
    [('a', '1'), ('b', '2'), ('c', '3')]
    [('a', '1'), ('b', '2'), ('c', '3')]
    [('a', '1'), ('b', '2'), ('c', '3')]
    >>>


    Or, for that matter, even simpler examples like this:

    >>> bag = "abc"
    >>> for x in bag: print(x)

    ....
    a
    b
    c
    >>> for x in bag: print(bag)

    ....
    abc
    abc
    abc
    >>>


    And this:

    >>> a, b, c = bag
    >>> a, b, c

    ('a', 'b', 'c')
    >>> bag

    'abc'
    >>>


    Go to the Python command line and try things out.
     
    Jussi Piitulainen, Jan 10, 2012
    #9
  10. "???????? ??????" <> wrote in message
    news:...
    >
    > 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?


    No. 'for host, hits, agent, date in dataset:' is equivalent to -

    for row in dataset: # iterate over the cursor, return a single row (tuple)
    for each iteration
    host, hits, agent, date = row # unpack the tuple and assign the elements
    to their own names

    For the first iteration, row is the tuple ('foo', 7, 'IE6', '1/1/11')
    For the next iteration, row is the tuple ('bar', 42, 'Firefox', '2/2/10')
    For the next iteration, row is the tuple ('baz', 4, 'Chrome', '3/3/09')

    The original line uses a python technique that combines these two lines into
    one.

    HTH

    Frank Millman
     
    Frank Millman, Jan 10, 2012
    #10
  11. Am 10.01.2012 12:37 schrieb Îικόλαος ΚοÏÏας:

    > 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)


    No.

    As said, dataset is the whole result set. For now, you can see it as a
    list of all rows (which you get if you do l=list(dataset)).

    Let's assume you have your data in a list now, which is equivalent
    concerning the iteration.

    Then you have something like

    dataset = [
    ('foo',7,'IE6','1/1/11'),
    ('bar',42,'Firefox','2/2/10'),
    ('baz',4,'Chrome','3/3/09')
    ]


    Doing

    for row in dataset: print row

    is equivalent to

    row = ('foo',7,'IE6','1/1/11')
    print row

    row = ('bar',42,'Firefox','2/2/10')
    print row

    row = ('baz',4,'Chrome','3/3/09')
    print row



    Doing

    for a, b, c, d in dataset:
    do_funny_stuff(a, d, c, b)

    is

    a, b, c, d = ('foo',7,'IE6','1/1/11');
    # which is the same as
    # a = 'foo'; b = 7; c = 'IE6'; d = '1/1/11';
    do_funny_stuff(a, d, c, b)

    a, b, c, d = ('bar',42,'Firefox','2/2/10')
    do_funny_stuff(a, d, c, b)

    a, b, c, d = ('baz',4,'Chrome','3/3/09')
    do_funny_stuff(a, d, c, b)


    The "body" of the for suite is executed once for each element.

    You have read already

    http://docs.python.org/tutorial/controlflow.html#for-statements
    http://docs.python.org/library/stdtypes.html#iterator-types

    ?


    Thomas
     
    Thomas Rachel, Jan 10, 2012
    #11
  12. Íéêüëáïò Êïýñáò

    Nick Dokos Guest

    Îικόλαος ΚοÏÏας <> wrote:

    > On 10 Ιαν, 03:11, Ian Kelly <> wrote:
    > > 2012/1/9 Ãéêüëáïò Êïýñáò <>:
    > >
    > > > if the MySQL query was:

    > >
    > > > cursor.execute( '''SELECT host, hits, agent, date FROM visitors WHEREpin =
    > > > %s ORDER BY date DESC''', pin )

    > >
    > > > can you help me imagine how the mysql database cursor that holds the query
    > > > results would look like? I must somehow visualize it in order to understand
    > > > it!

    > >
    > > You can think of it as a pointer, traversing over one row of the
    > > result set at a time.  Hopefully this will come out legibly:
    > >
    > > -----------------------------------------------
    > > | HOST | HITS | AGENT | DATE |
    > > -----------------------------------------------            -------------
    > > | foo     | 7       | IE6      | 1/1/11 |   <----   | cursor |
    > > -----------------------------------------------            -------------
    > > | bar     | 42     | Firefox  | 2/2/10 |
    > > -----------------------------------------------
    > > | baz    | 4       | Chrome | 3/3/09 |
    > > ------------------------------------------------

    >
    > Database cursor is the pointer that iterates over the result set one
    > row at a time?
    > I though that it was the name we give to the whole mysql result set
    > returned my cursor.execute.
    >
    > >
    > >
    > > > Also what happend if the query was:
    > > > cursor.execute( '''SELECT host FROM visitors") ?

    > >
    > > > the result would have to be something likelike?

    > >
    > > > -----------------
    > > > |somehost1|
    > > > -----------------
    > > > |somehost2|
    > > > -----------------
    > > > |somehost3|
    > > > -----------------
    > > > .....................
    > > > .....................
    > > > |somehost n|
    > > > -----------------

    > >
    > > > So what values host, hits, agent, date would have in 'for host, hits, agent,
    > > > date in
    > > >  dataset' ? Every row has one string how can that be split in 4?

    > >
    > > Why don't you try it and see what happens?  But to spare you the
    > > suspense, you would get:
    > >
    > > ValueError: need more than 1 value to unpack
    > >
    > > Because you can't unpack a 1-length tuple into four variables.  The
    > > code assumes that the query is selecting exactly 4 columns.

    >
    >
    > -----------------------------------------------
    > | 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?
    >
    > I still have trouble understanding this line :(


    You can think of it as a list of tuples. Forget about cursors and
    databases for now. If l is a list [1, 2, 3, 4] you iterate over it like
    this:

    for x in l:
    print x

    and you get each element of the list[fn:1]. Similarly if l is a list of tuples
    l = [(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)] you can iterate over the
    list:

    for x in l:
    print x

    In this case, x is going to be (1,2,3,4) the first time through the loop, (5,6,7,8)
    the second time and so on. You can break each x apart within the loop:

    for x in l:
    t1, t2, t3, t4 = x
    print x, t1, t2, t3, t4

    or you can break it apart like this - it's essentially the same thing:

    for t1, t2, t3, t4 in l:
    print t1, t2, t3, t4

    You have been encouraged repeatedly to try these things interactively:
    please do so with the above examples and all will become clear.

    Going back to cursors and databases: you *can* think of 'dataset' as
    being a list of tuples - a list of all the query results, but with one
    proviso. The difference when you use a cursor is that `dataset' may
    be a lazy list (an "iterator"): instead of the whole set of results
    being in memory at the same time, the system will take care of doing
    whatever is necessary to get more of the results when it needs them. But
    the behavior is the *same* in the sense that the output that you get is
    the same (you will only see differences if you are keeping an eye on how
    much memory and how much time your program is using).

    Nick

    Footnotes:

    [fn:1] ... and, no, you *can't express* this as
    "the first time it is

    for x in 1:
    ...

    and the second time it is

    for x in 2:
    ...

    " as you asked in another email. That's arrant nonsense: x takes
    successive values in the list l for every iteration of the for
    loop. This is elementary Python (nay, elementary programming, period).
     
    Nick Dokos, Jan 10, 2012
    #12
  13. Íéêüëáïò Êïýñáò

    RainyDay Guest

    On Jan 10, 6:37 am, Íéêüëáïò Êïýñáò <> wrote:
    > On 10 Éáí, 12:57, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > 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?



    It maps naturally to a phrase 'for page in a book'. Book refers
    to a complete book with all pages, but 'for page in a book' refers
    to each page, one by one. 'for each page in book: turn it'. The
    meaning is to turn each page, so your question is equivalent
    to asking 'so book is one page at each time'? No, it is not
    and doesn't have to be (unless it's a really short book!)

    -ak
     
    RainyDay, Jan 11, 2012
    #13
  14. On 10 Ιαν, 17:24, Nick Dokos <> wrote:

    > You have been encouraged repeatedly to try these things interactively:
    > please do so with the above examples and all will become clear.


    I tried all those examples you provided me in IDLE and finally graps
    they idea behind it.

    Thanks for all your detailed explanations and the patience you showed
    me until i finally understood this concept.
     
    Îικόλαος ΚοÏÏας, Jan 11, 2012
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mariusz

    explanation

    Mariusz, Jan 12, 2004, in forum: VHDL
    Replies:
    1
    Views:
    598
    tbx135
    Jan 13, 2004
  2. Kaladhaur Palaniappa

    Need Explanation

    Kaladhaur Palaniappa, Aug 7, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,009
    Kaladhaur Palaniappa
    Aug 7, 2003
  3. Benjie Fallar

    tracing output explanation

    Benjie Fallar, Jul 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    361
    Benjie Fallar
    Jul 15, 2003
  4. George Ter-Saakov

    Do you have an explanation for this?

    George Ter-Saakov, Apr 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    590
    Pravin A. Sable
    Apr 30, 2004
  5. Dave
    Replies:
    4
    Views:
    397
Loading...

Share This Page