Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18727

Re: Explanation about for

References <e1a94d90-57b4-4f6c-be9a-bef08f978639@h13g2000vbn.googlegroups.com> <CALwzidmkSPAQBUxHTUWdoj+QKTR91UO_EPoMxr+2G+Qcy4PZdw@mail.gmail.com> <CAGeFqcC=hc5xMgwqLAbdMR=cCdjYVhAbQvS9yeaxMH=o766_mA@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-01-09 18:11 -0700
Subject Re: Explanation about for
Newsgroups comp.lang.python
Message-ID <mailman.4567.1326157923.27778.python-list@python.org> (permalink)

Show all headers | View raw


2012/1/9 Νικόλαος Κούρας <nikos.kouras@gmail.com>:
> 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Explanation about for Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-09 15:23 -0800
  Re: Explanation about for Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-09 16:42 -0700
  Re: Explanation about for Chris Rebert <clp2@rebertia.com> - 2012-01-09 15:58 -0800
  Re: Explanation about for Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-09 18:11 -0700
    Re: Explanation about for Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-10 01:02 -0800
      Re: Explanation about for Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-01-10 11:57 +0100
        Re: Explanation about for Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-10 03:38 -0800
          Re: Explanation about for Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-01-10 14:52 +0200
        Re: Explanation about for Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-10 03:37 -0800
          Re: Explanation about for "Frank Millman" <frank@chagford.com> - 2012-01-10 15:39 +0200
          Re: Explanation about for Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-01-10 16:22 +0100
          Re: Explanation about for RainyDay <andrei.avk@gmail.com> - 2012-01-11 14:39 -0800
      Re: Explanation about for  Nick Dokos <nicholas.dokos@hp.com> - 2012-01-10 10:24 -0500
        Re: Explanation about for Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2012-01-11 14:50 -0800

csiph-web