6,497 questions
Tooling
2
votes
2
replies
91
views
What does the yield keyword do in Python, and when should I use a generator instead of a list?
I'm trying to optimize a function that processes a very large file line by line. I’ve seen some examples use the yield keyword, but I don't fully understand how it differs from return. When I use ...
1
vote
0
answers
63
views
How to deal with blocking generator values?
I'm trying to read .cif files (chemistry) using Pythons openbabel. For most files in my database this works perfectly fine, regardless of their size. For a handful of files, however, my code blocks ...
4
votes
3
answers
162
views
Generator that yields True a fixed number of times at random intervals before exhausting
I want to iterate through a list of size n, with A 1s in it (the rest are 0s), and I want the 1s randomly distributed.
n and A are large, so I'm trying to make a generator instead of a list.
If they ...
1
vote
4
answers
77
views
When does python 3 execute the beginning of a generator function?
Python 3 seems not to execute the beginning of a generator function, from its first line up to the first yield at the time when the function is first called. Python seems to defer the initial ...
1
vote
2
answers
87
views
vobject.readcomponents(...) : Is it a generator or does it *return* a generator?
This is a question about technical terminology.
The vobject documentation says "readComponents is a generator", which is consistent with its doc string "Generate one Component at a time ...
0
votes
1
answer
143
views
How to save a generator output (dict with nested list) to the json format?
I have a python generator that yields a sample (np.ndarray, size: batchsize x ndim) of a larger dataset (np.ndarray, size: ndata x ndim).
I coded a decorator that yields a processed output (dict) of ...
0
votes
1
answer
53
views
Returning await anext(gen) from function results in exception
While refactoring a middleware interceptor function, I moved this code for getting the db session:
if get_async_session in request.app.dependency_overrides:
get_session = request.app....
3
votes
0
answers
127
views
Compiling std::generator with optimization produces null-dereference in GCC
cppreference.com gives an example on how to use the c++23 std::generator.
From https://en.cppreference.com/w/cpp/coroutine/generator.html:
#include <generator>
#include <iostream>
...
-3
votes
1
answer
117
views
Can two equivalent JavaScript generators be derived from each other?
I have two JavaScript generator functions for permutations. They both provide Heap's enumeration.
Question: I would like to know whether one implementation can be derived from the other by some ...
0
votes
0
answers
30
views
Dialogflow CX Generator's response always haas an \n at the end
I was using generators in Dialogflow CX and every output response has a "\n" in the end even after fine tuning the prompt and I even tried it with simple output generations instead of ...
0
votes
0
answers
59
views
Make my Tensorflow dataset generator more efficient in training
I have built a Tensorflow Dataset from a generator but it seems to be very slow when training. In testing I cut the size of the dataset greatly and the training is much faster when uploaded as a ...
2
votes
2
answers
141
views
Problems creating a generator factory in python
I'd like to create a generator factory, i.e. a generator that yields generators, in python using a "generator expression" (generator equivalent of list comprehension). Here's an example:
...
1
vote
0
answers
78
views
Copy a generator via ctypes
I'm trying to copy a generator by using PyGen_New by passing in a frame object. Thus far, I get the following error that I don't understand:
Traceback (most recent call last):
File "C:\test.py&...
0
votes
0
answers
128
views
How to process large files efficiently with generators in Python without memory issues?
I’m working on a data processing pipeline in Python that needs to handle very large log files (several GBs). I want to avoid loading the entire file into memory, so I’m trying to use generators to ...
0
votes
1
answer
60
views
using an async generator function for better-sqlite3 db.table
I have used a db.table() function with better-sqlite3 successfully. But, I am now trying to implement an async function and get an error
db.table('Foo', {
columns: [ 'col' ],
rows: async ...