generator no iter - how do I call it from another function

Steve D'Aprano steve+python at pearwood.info
Sat Oct 1 07:15:13 EDT 2016


On Sat, 1 Oct 2016 06:52 pm, Sayth Renshaw wrote:

> Evening
> 
> My file list handler I have created a generator.
> 
> Before I created it as a generator I was able to use iter on my lxml root
> objects, now I cannot iter.

lxml root objects have an iter method. Other objects do not.


Thank you for showing your code, but it is MUCH too complicated. Most of the
code has nothing to do with your question. You are asking a question about
generators, but your code shows argument processing, file processing,
regexes, all sorts of things that we have to read and understand before we
can answer your question, and none of it is relevant.

That's too much work. We are volunteers. If you want to pay us, we'll be
happy to spend hours on your code. But if you want free consulting, then
you have to do some of the work to make it easy for us.

Please cut your code down to the smallest possible amount that shows the
problem:

http://sscce.org/

If you have a generator, you can iterate over it like this:

def generator():
    yield 1
    yield 2
    yield 4


for value in generator():  # NOT generator.iter()
    print(value)


Does that answer your question? If not, then cut your code down to the
smallest possible amount that shows the problem:

http://sscce.org/

and I'll read it again.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list