Thanks for the feedback. Because of comments like these, I decided to spend more time at training people for a living, and I'm loving it.
So don't underestimate the power of web comments, it can literally change the way people live.
41–50 of 53 posts
Thanks for the feedback. Because of comments like these, I decided to spend more time at training people for a living, and I'm loving it.
So don't underestimate the power of web comments, it can literally change the way people live.
Earlier quoted context omitted.
I think I mostly understand the idea, the presence of the yield statement transforms the nature of the parent function itself and makes evaluation lazy. This seems a little weird syntactically though because it feels like the interpreter is somehow reading ahead in the program. It also means you don't necessarily know that this is a lazy function unless you read to the end. A more intuitive syntax might be something…
This syntax would against the Python principle DRY (Don't Repeat Yourself): The "lazy" keyword conveys no information that doesn't exist in the function body. Also, Python has precedent for this scanning behavior. One of the fundamental features of Python is that the scope of a variable is determined by the presence of an assignment statement in a function. For example: a = 1 def f(): print a # UnboundLocalError occu…
A specific syntax for generators would in my view be generally superior, containing the same number of new keywords (generator now replacing yield) and providing enhanced clarity.
generator hello(n):
for i in range(n):
return i
I am generally neutral about variable scope being determined by the assignment of a statement in a function - in 99.99% of cases the intuitive thing happens.Earlier quoted context omitted.
This syntax would against the Python principle DRY (Don't Repeat Yourself): The "lazy" keyword conveys no information that doesn't exist in the function body. Also, Python has precedent for this scanning behavior. One of the fundamental features of Python is that the scope of a variable is determined by the presence of an assignment statement in a function. For example: a = 1 def f(): print a # UnboundLocalError occu…
This is an insightful point. I tend to regard this scanning behaviour as a "quirk" rather than something fitting in more with some deeper Python philosophy. A specific syntax for generators would in my view be generally superior, containing the same number of new keywords (generator now replacing yield) and providing enhanced clarity. generator hello(n): for i in range(n): return i I am generally neutral about variab…
Earlier quoted context omitted.
This is an insightful point. I tend to regard this scanning behaviour as a "quirk" rather than something fitting in more with some deeper Python philosophy. A specific syntax for generators would in my view be generally superior, containing the same number of new keywords (generator now replacing yield) and providing enhanced clarity. generator hello(n): for i in range(n): return i I am generally neutral about variab…
Except you can use `return` without argument to return early from a generator, and `yield` without argument yields None, so they need to be separate keywords.
Hi guys, I'm the autor of the answers. Thanks for the feedback. Because of comments like these, I decided to spend more time at training people for a living, and I'm loving it. So don't underestimate the power of web comments, it can literally change the way people live.
def y():
yield 1
yield 2
for i in y():
print iHi guys, I'm the autor of the answers. Thanks for the feedback. Because of comments like these, I decided to spend more time at training people for a living, and I'm loving it. So don't underestimate the power of web comments, it can literally change the way people live.
Great stuff. I do like to see the simplest possible exposition of any idea/technique though; here's my attempt at a simplest possible. def y(): yield 1 yield 2 for i in y(): print i
Earlier quoted context omitted.
Except you can use `return` without argument to return early from a generator, and `yield` without argument yields None, so they need to be separate keywords.
This functionality is so arcane that it's not needed.
Earlier quoted context omitted.
This functionality is so arcane that it's not needed.
Early return is definitely needed. I guess you could make bare `return` early return, and `return None` the way to yield None, but that's kind of confusing.
Earlier quoted context omitted.
Early return is definitely needed. I guess you could make bare `return` early return, and `return None` the way to yield None, but that's kind of confusing.
I agree that would be confusing, but I question that early return is needed - I don't think I've ever seen a generator example where early return is used. It could be that it's because I haven't seen enough examples of course. Please share some examples of a generator with early return which can't be accomplished easily and clearly in some other way.
def first10(*iterables):
n = 0
for iterable in iterables:
for item in iterable:
yield item
n += 1
if n == 10:
returnEarlier quoted context omitted.
I studied computer science at a university, not just a college, and coroutines weren't covered during the course. So even if you've got a degree, there's no guarantee you'll have met a coroutine! (I do agree that a formal education is valuable, even if you already think (or know) you're good at programming. I learned a lot from my course. There's a lot to be said for being forced to learn a bunch of stuff, and when y…
> at a university, not just a college College is (most of the time) American for university.