yield turns a function into a generator. What this means is that now, whenever you iterate over the generator, it will return a value, which is 'yielded' from the generator.
This gives some nice properties, like you do not need to return all values at once (saves memory) or allows to abstract data retrieval (e.g. you write a generator which returns rows from SQL Table).
e.g. a generator which returns odd numbers:
def yield_odd(): current_number = 1
while True: current_number += 2 yield current_number
# this will go on forever for i in yield_odd(): print(i)
Isaiah Collins
Is it a good idea to write android apps with kivy?
Jordan Johnson
I never tried it, but if you can, try writing it as a web app, rather than native. Easier portability and maintenance.
Luis Morgan
Thanks, seems useful. I'll try it out.
Dylan Perry
currently going from python -> clojure for hobby programming, but still using python for work.
flask json api / deep learning / NLP / scripting general
Overall 9/10 language, only thing that needs fixing is the concurrency model. Maybe python 3 fixed that but I haven't tried it so idk.
Cameron Morris
Don't believe his lies. Generating rows from SQL databases makes no performance increase.
Jordan Flores
Is there an NLP framework like spaCy that doesn't require so much training data? I'm unfamiliar with how NLP works but the spaCy similarity() function to analyze the sentiment of two strings works really well and handles, I assume, tokenization etc. behind the scenes which other frameworks don't seem to do. I don't mind losing accuracy at the expense of freeing up disk space.
Robert Russell
1) Fetching data in batches of e.g. 1000 rows per batch is better than fetching everything in one go 2) Abstracting the code to connect to db, query it and retrieve the results, makes the code easier to read
Jayden Garcia
Can i hack NSA with this?
Colton Lee
That has nothing to do with generators. The SQL connector will push as many rows into the socket as fast as he can. You pulling them out one by one with a generator or iterator or enumerator makes no difference.
It would only make a difference if you were accessing the database itself, not through a connector.
A better example of generators is statistics, mathematical sequences (taylor, fibonacci) and shit.
Jose Barnes
It will push as many as were generated by the SQL Statement. What I'm talking about is using LIMIT / OFFSET / TOP (whatever you're on) to retrieve a subset of rows and then in each subsequent iteration, change the offset in the SQL query to retrieve next batch.
Brandon Long
favorite out of the ordinary use for it?
Lucas Edwards
I'm using Python to compare laser scanning data. It's not going to be fun once I have to process very dense point clouds...
I should probably learn C
Samuel Smith
What's your view on list comprehensions?
Caleb Mitchell
>mfw a gentooman tells me to learn an embedded systems language instead
Ryder Gutierrez
Seems easy enough to me.
Jaxon Powell
nth for flask
Elijah Torres
I want to start learning python, what book should i buy?
Landon Clark
If you want to all out, the mouse book is pretty comprehensive.
Ethan Edwards
Thanks, i'll look at some reviews and probaly buy it
Colton Mitchell
Don't need to buy anything. You can start with the official documentation, which is pretty good