The Python `StopIteration` exception.
Questions tagged [stopiteration]
72 questions
3
votes
1 answer
Python3 StopIteration Error can not raise when using list(map(...))
At first I write this, and it raises StopIteration, works well.
it = iter([1])
iters = [it] * 2
for it in iters:
r = next(it)
print(r)
but when I changed to this:
it = iter([1])
iters = [it] * 2
r = list(map(next, iters))
print(r)
It can…

user1021531
- 487
- 1
- 7
- 16
3
votes
1 answer
StopIteration error with a generator in python
The error asks for a StopIteration statement, which already exists and I may have just placed it in the wrong section of code. I can't find any use of a generator that is similar to this. The error:
Traceback (most recent call last):
File "W:\My…

M G.
- 33
- 1
- 3
3
votes
2 answers
Ignore StopIteration
I just read a bunch of posts on how to handle the StopIteration error in Python, I had trouble solving my particular example, though. Basically, I have a csv file with a lot of prefixes. This file has two columns with headers: Word and Count. Count…

user1590499
- 933
- 3
- 10
- 17
2
votes
2 answers
Python seaborn histplot returns StopIteration
I installed seaborn, but when I do the example from the Seaborn website, I get StopIteration message, how do I fix it?
import seaborn as sns
penguins = sns.load_dataset("penguins")
sns.histplot(data=penguins, x="flipper_length_mm")
StopIteration …

Ray Hu
- 31
- 2
2
votes
2 answers
Do iterators have to stop forever after raising StopIteration?
I have a Receiver object that will sometimes accumulate a queue of packets that will be consumed when processed. It seems reasonable to make this receiver have an iterator protocol, so next( receiver ) will manually retrieve the next packet, and…

JustinFisher
- 607
- 1
- 7
- 10
2
votes
1 answer
StopIteration won't be caught in main()
I want to raise a StopIteration exception when the number I send is larger than 999999999.
When I sent to print(check_id_valid(1234567980)) function parameters directly or to IDIterator class (the iterator class) and from there the number pass to …
user13279074
2
votes
2 answers
Python StopIteration in generator comprehension
Python 3.6
Trying to write a function that returns the common string in a list of strings. Eg.
>>>find_common_string(*['test 1', 'test 2', 'test 3'])
would return
>>>'test '
I tried to prevent it from matching any other strings after the first…

James Schinner
- 1,549
- 18
- 28
2
votes
2 answers
StopIteration in Python
I encounter a problem while reading functional programming python.
def get_log_lines(log_file):
line = read_line(log_file)
while True:
try:
if complex_condition(line):
yield line
line =…

Jaron Tang
- 23
- 4
1
vote
1 answer
Program raised StopIteration error when using pattern library on Python
I want to use suggest function from pattern library in Python but I encountered an error.
I expected to see the output but it raised StopIteration error.
My code:
from pattern.en import sentiment, suggest
print(sentiment("What a mess…

umut_satir
- 13
- 4
1
vote
1 answer
Implementing my own Cycle function ( mocking itertools.cycle method)
Am new to Python and am trying to implement my own Cycle method mocking itertools.cycle method.
I have written the following code. It gives the output, but with an exception.
I want to understand why this exception is thrown and is there a way to…

Vijay
- 33
- 3
1
vote
1 answer
StopIteration when mocking base class of own class
In a rather complex test scenario I need to mock the base class of one of my own classes and instantiate the latter several times. When I do that my test errors with a StopIteration exception. Here's what my scenario boils down to in this…

Kai Roesner
- 429
- 3
- 17
1
vote
1 answer
StopIteration Error occurs during training while running the train.py file
I am trying to run a code from github. The file is called train.py. It is supposed to run a Neural Network for training on a dataset. However, I get the following error
(QGN) ubuntu@ip-172-31-13-114:~/QGN$ python train.py
Input arguments:
id …

Aamir Shah
- 31
- 7
1
vote
0 answers
Extracting 10 popular user from twitter with twitter api
I am trying to extract 10 popular(verified) users from Twitter which I follow but every time I am getting an error the error is
RuntimeError: generator raised StopIteration.
I am new to python and don't know where the code is wrong, so I am posting…

Coder-91
- 23
- 5
1
vote
1 answer
How can I improve my error handling so the exception StopIteration in Tweepy is processed correctly and execution can continue?
I have the following function to get the twitter followers and write them to a MySQL database. My problem is my error handling doesn't handle the StopIteration case very well.
When I execute the code it does write the details to the database in line…

mobcdi
- 1,532
- 2
- 28
- 49
1
vote
3 answers
Stop iterative function python that keeps iterating
I have a function below, that takes a value as an input, and determines a new_value (the new_value will always be less than the original_value). If the difference between the new_value and the original_value is less than a specified tolerance, the…

Anna
- 29
- 4