Questions tagged [stopiteration]

The Python `StopIteration` exception.

72 questions
0
votes
0 answers

Querying a mongodb raises stop iteration error

Using the following code, I am trying to extract two dates from an object in mongodb and then calculate the difference in time between the two dates -- if both year are in/past 2016. My current code raises the following error: DeprecationWarning:…
Graham Streich
  • 874
  • 3
  • 15
  • 31
0
votes
0 answers

extracting sub_folders of a path in python using next(os.walk(path))[1]

I have a python program and in my program, I want to manipulate folder and subfolders. When I use subfolders = next(os.walk(src))[1] command, I get this error: StopIteration I have no idea about this error. I print the path before rising the error…
Stateless
  • 293
  • 2
  • 4
  • 18
0
votes
1 answer

StopIteration given by a file iteration that uses nested loops

I'm having some issues with the following block of code. What I'm trying to do is go through a file line by line, and pull out the lines following a line that contains ".W", until it reaches a line that starts with ".I" with…
wtk219
  • 285
  • 1
  • 9
0
votes
2 answers

Python Wolfram Alpha API: StopIteration

How can I avoid the stopiteration error? I am unaware of any functions or loops that the code may be iterating through. import wolframalpha client = wolframalpha.Client('My Key is Goes Here') res = client.query('pi') print next(res.results).text
K. W. Cooper
  • 313
  • 3
  • 12
0
votes
0 answers

return value from generator in py3.2 *and* py3.5

In Python 3.3 and newer, you can return a value from a generator; we use this in Tornado to have functions that call big and slow subprocesses (translate_part below) without blocking the main thread, and also without having more than one of the…
unhammer
  • 4,306
  • 2
  • 39
  • 52
-1
votes
2 answers

StopIteration exception raised in a function

I have the following function in my python script: def subset_sum (list_of_int,target): #create iterable itr = chain.from_iterable(combinations(list_of_int, n) for n in range(2,len(list_of_int)-1)) #number of iteration rounds rounds…
-1
votes
1 answer

Why doesn't this code raise a StopIteration exception?

In this code I have class name Iter that contains Two dunder methods __iter__ and __next__. In __iter__method I set self.current equal to zero and return self. In next method I increase self.current += 1. When it reaches 10 I want it to raise a…
-1
votes
1 answer

StopIteration error/ exception/ bug while using multiple if condition and next()

I used jupyter notebook here. This code is from a youtube video. It was working in the youtuber's computer but mine raise a Stopiteration error Here I am trying to get all the titles(questions from the csv) that are questions related to 'Go'…
vedant
  • 1
  • 2
-1
votes
2 answers

How do I prevent my list comprehension from raising a stopIteration error

I'm stepping through a text file with records that are 3-lines long. If, in the first line, I can say "this is a record that I don't want to count", I want to move to the start of the next record, 2 lines further down. Currently, I'm running a…
phfb
  • 121
  • 2
  • 12
-1
votes
1 answer

How to solve the StopIteration issue while the XML tag does not have a value using Python script

I am using ixml to parse the XML doxument. from lxml import etree root=etree.XML(full xml tag file content) if (next(root.iterfind(".//one_inner_tag")).text is None): Print "NONE VALUE" else: Print…
sara
  • 115
  • 1
  • 2
  • 15
-2
votes
2 answers

Problem with using a function just once in a range

I have an assignment and couldn't figure out the true solution. def triple(n): #multiplies number with 3 return (n*3) def square(n): return (n**2) #takes second power of number for i in range(1,11): if triple(i) > square(i): …
-6
votes
2 answers

wolframalpha result stopiteration

I getting an error for my below code: import wolframalpha ask = input("Question:- ") app_id = "E82747-Y2LGY6EKH3" client = wolframalpha.Client(app_id) res = client.query(ask) answer = next(res.results).text print (answer) Error I am…
Vipul
  • 11
  • 1
1 2 3 4
5