Use next in iterator objects
See original GitHub issuePython 3.7 vt-py 0.5.4
import vt
client = vt.Client(VT_API_KEY)
query = 'entity:domain p:0 urls_max_detections:10+'
attacked_legit_domains = client.iterator('/intelligence/search', params={'query': query}, limit=1)
legit_domain = next(attacked_legit_domains)
Traceback:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-806f21dacbfe> in <module>()
2 attacked_legit_domains = client.iterator('/intelligence/search', params={'query': query}, limit=1)
3
----> 4 legit_domain = next(attacked_legit_domains)
TypeError: 'Iterator' object is not an iterator
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Python next() - Programiz
In this tutorial, we will learn about the Python next() function with the help of examples. The next() function returns the next item...
Read more >How to use Iterator in Java? - GeeksforGeeks
Object next (): It returns the next element in the collection until the hasNext()method return true. This method throws 'NoSuchElementException' ...
Read more >Python Iterators - W3Schools
An iterator is an object that can be iterated upon, meaning that you can traverse through all the values. Technically, in Python, an...
Read more >Iterators and generators - JavaScript - MDN Web Docs
Once created, an iterator object can be iterated explicitly by repeatedly calling next() . Iterating over an iterator is said to consume the ......
Read more >Python Iterators - iter() and next() - Pylenin
Iterators are objects that manage iteration over an iterable. An iterator has an iteration set - it knows the current element and also...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @carlosjcabello,
Reading PEP 525, I understand they wanted to iterate over generators using
async for
without implementing an iterator obejct. Compare the following outputs (Python 3.5 vs Python 3.9):That said, the code is actually implementing an iterator per sé, so the implementation you did is more correct in terms of the concept being implemented than the implementation made at #12.
Regards, Marta
Hi Marta,
Thanks for the additional details.
I created the draft PR https://github.com/VirusTotal/vt-py/pull/68 based on https://github.com/VirusTotal/vt-py/issues/24#issuecomment-893567216. On it,
__iter__
and__aiter__
simply return the instanceself
and all the iteration logic is moved to__next__
and__anext__
methods.Elaborating more on my previous comment, what I mean is that there was a similar implementation before https://github.com/VirusTotal/vt-py/pull/12. That PR changed the iterator implementation to be based on generators. As @chexca and @plusvic mentioned, it made the code simpler. But it had as a consequence that ‘Iterator’ class instances were not iterators objects. Now we are changing the implementation again, moving away from generators.
Just wanted to know if there was a consensus at VT on this. That is, that the proposed solution is preferred over the generator-based implementation.