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


Groups > comp.lang.python > #65256

Re: generator slides review

Path csiph.com!usenet.pasdenom.info!gegeweb.org!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <andrea.crotti.0@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'odd': 0.07; '[1,': 0.09; 'assuming': 0.09; 'generators': 0.09; 'implements': 0.09; 'cc:addr:python-list': 0.11; 'anyway': 0.14; 'buggy': 0.16; 'comments:': 0.16; 'coroutines': 0.16; 'creation.': 0.16; 'defined.': 0.16; 'entry.': 0.16; 'evaluates': 0.16; 'exception?': 0.16; 'iterator': 0.16; 'iterator,': 0.16; 'iterators': 0.16; 'reedy': 0.16; 'subject:generator': 0.16; 'think?': 0.16; 'valid.': 0.16; 'valueerror': 0.16; 'wrote:': 0.18; 'work,': 0.20; 'example': 0.22; '(in': 0.22; 'saying': 0.22; 'cc:addr:python.org': 0.22; 'non': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'pass': 0.26; 'defined': 0.27; 'header:In-Reply- To:1': 0.27; 'idea': 0.28; 'correct': 0.29; 'fixed': 0.29; 'leave': 0.29; 'am,': 0.29; 'raise': 0.29; 'label': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'about.': 0.31; 'assert': 0.31; 'values.': 0.31; 'lists': 0.32; 'probably': 0.32; 'quite': 0.32; 'implemented': 0.33; 'maybe': 0.34; 'could': 0.34; 'something': 0.35; 'definition': 0.35; 'more,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'done': 0.36; 'next': 0.36; 'thanks': 0.36; 'should': 0.36; 'wrong': 0.37; 'list': 0.37; 'clear': 0.37; 'feedback': 0.38; 'sometimes': 0.38; 'explain': 0.39; 'bad': 0.39; 'generating': 0.39; 'how': 0.40; 'even': 0.60; 'expression': 0.60; 'range': 0.61; 'simple': 0.61; 'first': 0.61; 'act': 0.63; 'show': 0.63; 'such': 0.63; 'more': 0.64; 'different': 0.65; 'great': 0.65; 'specialized': 0.65; 'yes': 0.68; 'wish': 0.70; 'inline': 0.74; '(better': 0.84; 'andrea': 0.84; 'confusing': 0.84; 'seldom': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=FPoirqfyYFDnQBFpghrD4OFJg7UwPrVatQnfC6L4cgo=; b=NsNysikaH+hQ6Nx7UX511mSVVHLezDxfnv1y3ESaffgMBzy3CIREFiqVnKmxIB2EHj TtIJjCCU03DF/nu90kmQhs35qyrkk7TEojDHFqN9RDEqLYQdXkJlLzitvod8JmVzpNGu CuUaHOdEp5rXnybS9k1pHGM/scMC8sxUX6FB6j6PxIa1+U8N44S3ntIn+vhwE2NoZCmY GuijnvZu/ki4VcBgKUDR7G3KFEUFAQhp2cxYM2ThGoz9d3vW/WWD4SNDKFnGrc0VSfTG Te26KJSDpGqa/xWwTuxDDjvM+qZS2mDnQM73vcZ82rNx2q1/TYWAblFgMwqs3kVQkeMD R5Gw==
MIME-Version 1.0
X-Received by 10.221.34.211 with SMTP id st19mr24274938vcb.5.1391337611401; Sun, 02 Feb 2014 02:40:11 -0800 (PST)
In-Reply-To <lck5pr$reg$1@ger.gmane.org>
References <CAF_E5JYWZXkq98ri63BMQst3kpPVhO1K5xQbQ0ZHCuRTYZXvUA@mail.gmail.com> <lck5pr$reg$1@ger.gmane.org>
Date Sun, 2 Feb 2014 10:40:11 +0000
Subject Re: generator slides review
From andrea crotti <andrea.crotti.0@gmail.com>
To Terry Reedy <tjreedy@udel.edu>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list <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.6301.1391337953.18130.python-list@python.org> (permalink)
Lines 79
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391337953 news.xs4all.nl 2934 [2001:888:2000:d::a6]:52915
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65256

Show key headers only | View raw


2014-02-02 Terry Reedy <tjreedy@udel.edu>:
> On 2/1/2014 9:12 AM, andrea crotti wrote:
>
> Comments:
>
> The use is assert in the first slide seem bad in a couple of different
> respects.
>

Why is it bad? It's probably not necessary but since we ask for a
range it might be good to check if the range is valid.
Maybe I should raise ValueError instead for a better exception?

> The use of 'gen_even' before it is defined.
>

Well this is because l'm saying that I wish I had something like this,
which I define just after. It might be confusing if it's not defined
but I thought it's nice to say what I would like to do and then
actually define it, what do you think?


> A generator expression evaluates (better than 'yields') to a generator, not
> just an iterator.
>

Ok thanks fixed

> The definition of 'generator' copies the wrong and confused glossary entry.
> Generator functions return generators, which are iterators with extra
> behavior.
>

I understood instead that it was the opposite, a generator is a
specialized iterator, so it would be still correct that it returns an
iterator, is that wrong?

> I would leave out For loop(2). The old pseudo-getitem iterator protocol is
> seldom explicitly used any more, in the say you showed.
>

This was mainly to explain how something like
for el in [1, 2, 3]:
    print(el)

can work, assuming defining an object list-like that just implements
__getitem__.
It's not probably how it's implemented for lists but I thought it
could clarify things..

> In 'Even numbers', I have no idea what the complication of next_even() is
> about.
>
Just because I wanted to find a simple way to get the next even (in
case I pass an odd start number).
I could also do inline but I thought it was more clear..

> 'Lazyness drawbacks' overflow_list is bizarre and useless.  overflow_gen is
> bizarre and buggy. If you are intentionally writing buggy code to make a
> point, label it as such on the slide.
>

Yes this is intentionally buggy. The thing is that I wanted to show
that sometimes generating things makes it harder to debug, and delays
some errors, which are anyway there but would come up immediately in
case of a list creation.
I could not find a better non artificial example for this, any
suggestion is welcome..


> Iterators just produce values. Generators can consume as well as produce
> values, which is why they can act as both iterators and coroutines.
>

Well is not more clear to call them in a different way since they do
quite a different job as coroutines or generators? (I see this done
quite often)

Thanks a lot for the great feedback

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


Thread

Re: generator slides review andrea crotti <andrea.crotti.0@gmail.com> - 2014-02-02 10:40 +0000

csiph-web