Questions tagged [stopiteration]

The Python `StopIteration` exception.

72 questions
1
vote
3 answers

Iteration through a list

I'm very new to Python hence this question. I have a list that represents dates i.e. Mondays in March and beginning of April [2, 9, 16, 23, 30, 6] The list, 'color_sack' is created from a scrape of our local council website. Im…
1
vote
4 answers

Don't know why I am getting StopIteration error

I am writing a program that takes in input from a file and each line may contain "ATG" or "GTG" and I am pretty sure I have done everything right as far as what I am trying to do. IT is my first time using a generator in python and after researching…
Tyler Dunn
  • 31
  • 6
1
vote
0 answers

Handing StopIteration in Python

I tried to code and get the right fitness_point here but after the loop the result keep showing as 0. It first showing the StopIteration, so I write try and except there, but the result is still wrong.. I am a completely newbie here, what should I…
1
vote
2 answers

Is StopIteration raised in the mapping function of python 3 map() handled incorrectly?

Consider the following example: def fn(x): if x > 2: raise StopIteration return x results = list(map(fn, range(5))) print(results) When I run this with python 2, I get what I expected: Traceback (most recent call last): File…
marcelka
  • 253
  • 3
  • 11
1
vote
0 answers

How to get the StopIteration value on leaving the for loop

I saw that there are two new features in Python 3: StopIteration can be given a value by a return statement for loop has the else part that is executed when the StopIteration happens Seems that it is reasonable to be able to work with the…
uk-ny
  • 51
  • 5
1
vote
3 answers

StopIteration after defining xrange

I wrote the following code to define blocks of 4 lines in a text file and output the block if the 2nd line of the block is composed of only one type of character. It is assumed (and previously verified) that the 2nd line is always composed of a…
biohazard
  • 2,017
  • 10
  • 28
  • 41
1
vote
1 answer

Capture StopIteration Error Message in For Loop

I have code similar to this structure: def my_gen(some_str): if some_str == "": raise StopIteration("Input was empty") else: parsed_list = parse_my_string(some_str) for p in parsed_list: x, y = p.split() …
Mo2
  • 1,090
  • 4
  • 13
  • 26
1
vote
2 answers

Would a StopIteration make python slow?

As far as i know, monitoring exception will make a program slower. Would an iterator exception monitor, such as StopIteration make a for loop slower?
user890973
  • 947
  • 2
  • 8
  • 12
0
votes
2 answers

StopIteration is being raised and I can't understand why (using next method)

I want my code to understand a string as a math expression, then output me this string with proper whitespaces. At first, I created my variables. operators = ("+", "-", "*", "/", "%", "**", "//") # Math operators the code is going to identify in…
Dariiu
  • 35
  • 5
0
votes
0 answers

how can I avoid the StopIteration note in python

I keep getting the StopIteration note when performing my code, my output is just to test if the code works as the whole thing involves retrieving data using an api. My code is showed as followed: import pandas as pd import json import requests from…
0
votes
2 answers

Python Iterator based on sorted column with various length

I was trying to write an iterator class in Python that can do a loop for a txt file, in while I would like to group all lines with identical value in the second…
Zewei Song
  • 521
  • 2
  • 6
  • 13
0
votes
0 answers

Prevent iterator stop on exception

Is there a way to iterate over a complete sequence (that I do not control), even if it raises an exception? For example, the following code does not work because after an exception is raised a StopIteration follows. def do(gen): it = iter(gen) …
Hernan
  • 5,811
  • 10
  • 51
  • 86
0
votes
1 answer

Why am I getting the "stop iteration" error and how do I fix this?

I get the StopIteration error when I run the code below. I saw some other posts on stack overflow with this same error but not sure they fit this case. Why is this happening and how do I fix it? The goal is to break up a dataframe column into…
hector.h2913
  • 41
  • 2
  • 8
0
votes
2 answers

Selenium python stops iteration after the first five elements while there are more elements in the list

I am writing a code to download some files from a webpage. The code starts fine and there are 27 files to download, but after the first 5 downloads, I get a ElementClickInterceptedException error for the following elements. Can anyone tell me why…
Bakaveli
  • 1
  • 2
0
votes
0 answers

i got StopIteration error , how to solve this error

i am storing the names of each image in the filename array and labels associated with that image in labels array. so i wrote this code import numpy as np subdirs, dirs, files = os.walk('/content/all_images').__next__() m =…