Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(using': 0.07; 'modified': 0.07; 'python3': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:localhost': 0.09; 'yeah,': 0.09; 'python': 0.11; 'def': 0.12; '"hello': 0.16; "'from": 0.16; '*any*': 0.16; 'generator.': 0.16; 'preserves': 0.16; 'quit.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'route,': 0.16; 'wrote:': 0.18; "hasn't": 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'url:dev': 0.24; 'mon,': 0.24; 'values': 0.27; 'header:X -Complaints-To:1': 0.27; 'function': 0.29; 'chris': 0.29; '[1]': 0.29; 'am,': 0.29; 'skip:@ 10': 0.30; '(which': 0.31; 'run': 0.32; 'framework': 0.33; 'url:non-standard http port': 0.33; 'something': 0.35; 'but': 0.35; 'yield': 0.36; 'similar': 0.36; 'url:org': 0.36; 'list.': 0.37; 'starting': 0.37; 'server': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'called': 0.40; 'skip:u 10': 0.60; 'temporarily': 0.60; 'more': 0.64; 'jul': 0.74; 'listening': 0.74; '127.0.0.1': 0.84; 'otten': 0.84; 'suspicion': 0.84; 'state.': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: complete brain fart, it doesn't loop Date: Mon, 28 Jul 2014 09:09:21 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd8439.dip0.t-ipconnect.de User-Agent: KNode/4.11.5 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406531383 news.xs4all.nl 2858 [2001:888:2000:d::a6]:53692 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75299 Chris Angelico wrote: > On Mon, Jul 28, 2014 at 4:07 AM, Peter Otten <__peter__@web.de> wrote: >> By the way, Python has something similar to a function that temporarily >> interrupts execution but preserves state. It's called generator. > > Yeah, but I have a suspicion his web framework (which he hasn't > identified, but I suspect *any* web framework) won't be looking for a > generator :) More likely, what he wants is to collect up the return > values in a list, and then return ''.join() that list. It was just a guess, but as the OP uses bottle, here's a modified "hello world" from the bottle site : $ cat app.py from bottle import route, run @route('/hello') def hello(): yield "Hello " yield "World!" run(host='localhost', port=8080, debug=True) $ python3 app.py & [1] 3203 $ Bottle v0.12.7 server starting up (using WSGIRefServer())... Listening on http://localhost:8080/ Hit Ctrl-C to quit. $ python3 -c 'from urllib.request import urlopen; print(urlopen("http://localhost:8080/hello").read())' 127.0.0.1 - - [28/Jul/2014 09:07:15] "GET /hello HTTP/1.1" 200 12 b'Hello World!' $