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


Groups > comp.lang.python > #75287

Re: complete brain fart, it doesn't loop

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <shieldfire@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'stops': 0.07; 'snippet': 0.09; 'martin': 0.11; 'python': 0.11; 'def': 0.12; '>the': 0.16; 'ah,': 0.16; 'generator.': 0.16; 'loops': 0.16; 'preserves': 0.16; 'skip:0 40': 0.16; 'wrote:on': 0.16; 'wrote:': 0.18; 'thanks.': 0.20; '>>>': 0.22; 'email addr:gmail.com&gt;': 0.22; 'reset': 0.22; 'header:User-Agent:1': 0.23; 'mon,': 0.24; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'skip:g 30': 0.30; "skip:' 10": 0.31; '>>>>': 0.31; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'explains': 0.36; 'yield': 0.36; 'similar': 0.36; 'message-id:@gmail.com': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'temporarily': 0.60; 'jul': 0.74; '2014,': 0.84; 'otten': 0.84; 'url:apps': 0.91; 'state.': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version:content-type :content-transfer-encoding:subject:from:date:to:message-id; bh=YS3hsRcMQBODGVdM11Wi37HvAVbQY8fTpiqFa4SIRIs=; b=dMomQcPWsjqdTtLgwSsBz7TasHTifCVP6IA2vpFE/x8rVmFaZQxfbt1+Lp6Gs5Lrk9 pBcTgI+C3RRqyPkL7gpDpoUUn8WiehqipVdGEKl+YqZDJm3suxByscCr6cBhBnQvomPE mP2WHupFUogt1EQ7koDmb0AtRsv3M1/39elFzKFZOfI9DeJEzyUTjKCZPXMGyMZhyR+7 Ddf5MiKyxHs5zhjnoz1FhEGVCruVc16qDzgY8lXWUp2mj+gGB46FmQAOsZ0AlnQViikP YCtSJ5pazNODE15GWhGqJFUS/v+0NKi8j/IGUE0aXquGo5nQlkosRJlQq1oeCczVZz9W zBbA==
X-Received by 10.152.245.34 with SMTP id xl2mr14632403lac.50.1406488657800; Sun, 27 Jul 2014 12:17:37 -0700 (PDT)
User-Agent K-@ Mail for Android
X-Priority 3
In-Reply-To <lr3f5l$e4h$1@ger.gmane.org>
References <CAHXoDSB=W3S4gwc7aJO2AA6gtkz5VGQ5=y7hZ5tLL32AamjmXQ@mail.gmail.com> <CAPTjJmrdqBwuiuJHSAGCjRZoWsQzi_iFVJe=XD3m0nbGa9w_Cg@mail.gmail.com> <lr3f5l$e4h$1@ger.gmane.org>
MIME-Version 1.0
Content-Type multipart/alternative; boundary="----F65CBHGND5I0O1AUY83ZN2YBLZF1TF"
Content-Transfer-Encoding 8bit
Subject Re: complete brain fart, it doesn't loop
From Martin S <shieldfire@gmail.com>
Date Sun, 27 Jul 2014 21:17:32 +0200
To python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12369.1406488664.18130.python-list@python.org> (permalink)
Lines 69
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1406488664 news.xs4all.nl 2928 [2001:888:2000:d::a6]:60551
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75287

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Ah, thanks. Explains it all :) 

/martin 

On 27 Jul 2014, Peter Otten <__peter__@web.de> wrote:
>Chris Angelico wrote:
>
>> On Mon, Jul 28, 2014 at 3:53 AM, Martin S <shieldfire@gmail.com>
>wrote:
>>> I have this snippet in my web application. Question is why doesn't
>the
>>> stupid thing loop ten times? It loops exactly 1 time.
>>>
>>>   # Reset counter
>>>     counter = 0
>>>
>>>     while counter <= 10:
>>>
>>>         return "<p>Long line with games</p>"
>>>
>>>         counter=counter+1
>> 
>> When you hit the 'return', it stops the function immediately :)
>
>By the way, Python has something similar to a function that temporarily
>
>interrupts execution but preserves state. It's called generator.
>Compare:
>
>>>> def f():
>...     for i in range(3):
>...             return "<p>Long line with games</p>"
>... 
>>>> f()
>'<p>Long line with games</p>'
>>>> def g():
>...     for i in range(3):
>...             yield "<p>Long line with games</p>"
>... 
>>>> g()
><generator object g at 0x7fe9b3e7b690>
>>>> list(g())
>['<p>Long line with games</p>', '<p>Long line with games</p>', '<p>Long
>line 
>with games</p>']

-- Sent with K-@ Mail - the evolution of emailing.

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


Thread

Re: complete brain fart, it doesn't loop Martin S <shieldfire@gmail.com> - 2014-07-27 21:17 +0200

csiph-web