You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to do this better? I guess I could just return the paginator to the caller and iterate over there. Maybe use yield? I hope that somebody has some idiomatic way of doing this.
The text was updated successfully, but these errors were encountered:
swetashre
added
investigating
This issue is being investigated and/or work is in progress to resolve the issue.
and removed
investigating
This issue is being investigated and/or work is in progress to resolve the issue.
labels
Sep 13, 2019
Thank you for your post. The code you provided will return a empty list if the paginator does not contain any items. You can use can_paginate if you want to know whether the operation is pageable or not.
Hope it helps and please let me know if you are asking for something else or i am understanding your question wrong.
Thanks @swetashre this is exactly I was looking for. I wanted to collapse the following to a nested list comprehension but that fails. With can_paginate I can make it work though.
This might help. I noticed that each page has a KeyCount key, which tells you how many S3 objects are contained in each page. So if the first page from the paginator has a KeyCount of 0, then you know it's empty.
Like this:
paginator=client.get_paginator('list_objects_v2')
forpageinpaginator.paginate(Bucket='my-bucket', Prefix='my-prefix'):
ifpage['KeyCount'] ==0:
continue# empty page (should be the only page in the paginator)
I am trying to improve on this code:
Is there a way to do this better? I guess I could just return the paginator to the caller and iterate over there. Maybe use yield? I hope that somebody has some idiomatic way of doing this.
The text was updated successfully, but these errors were encountered: