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


Groups > comp.lang.python > #75305

Re: complete brain fart, it doesn't loop

References <CAHXoDSB=W3S4gwc7aJO2AA6gtkz5VGQ5=y7hZ5tLL32AamjmXQ@mail.gmail.com> <CAPTjJmrdqBwuiuJHSAGCjRZoWsQzi_iFVJe=XD3m0nbGa9w_Cg@mail.gmail.com> <lr3f5l$e4h$1@ger.gmane.org> <CAPTjJmqZC7YpaNzNRZrVgguBbpOsYS=arkydG_5n3n8EY_G=3g@mail.gmail.com> <lr4sv7$l3j$1@ger.gmane.org>
Date 2014-07-28 09:54 +0200
Subject Re: complete brain fart, it doesn't loop
From Martin S <shieldfire@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.12383.1406534049.18130.python-list@python.org> (permalink)

Show all headers | View raw


That's neat. I was only aware of the return version.

Anyway, got it working now, simplifying the code in the process. So
all was not lost.

/Martin S

2014-07-28 9:09 GMT+02:00 Peter Otten <__peter__@web.de>:
> 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
> <http://bottlepy.org/docs/dev/tutorial.html#quickstart-hello-world>:
>
> $ 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!'
> $
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Regards,

Martin S

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-28 09:54 +0200

csiph-web