Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'assign': 0.04; 'python': 0.08; 'combines': 0.09; 'host,': 0.09; 'iterate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'tuple': 0.09; '(tuple)': 0.16; '42,': 0.16; 'iteration,': 0.16; 'only?': 0.16; 'row': 0.16; 'substituting': 0.16; 'then:': 0.16; 'unpack': 0.16; 'wrote': 0.22; 'elements': 0.29; 'lines': 0.30; 'equivalent': 0.31; 'skip:( 20': 0.31; 'header:X-Complaints-To:1': 0.33; 'to:addr:python-list': 0.34; 'set.': 0.34; 'uses': 0.36; 'two': 0.37; 'but': 0.37; 'received:org': 0.38; 'represent': 0.39; 'to:addr:python.org': 0.40; 'frank': 0.64; 'received:41': 0.71; 'time?': 0.73; 'agent,': 0.91; 'technique': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: Explanation about for Date: Tue, 10 Jan 2012 15:39:14 +0200 References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> X-Gmane-NNTP-Posting-Host: 41-133-114-227.dsl.mweb.co.za X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 X-RFC2646: Format=Flowed; Original X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326202781 news.xs4all.nl 6926 [2001:888:2000:d::a6]:38129 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18759 "???????? ??????" wrote in message news:afd612b7-2366-40be-badf-13c97655f72d@o12g2000vbd.googlegroups.com... > > 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