Get first item from search
Is it possible to retrieve the first item in one line without looping over it and breaking?
items1 = client.search().query(query="22",limit=1, ancestor_folder_ids=["159631784184"], sort="modified_at")
for item in items1:
print(f'The item ID is {item.id} and the item name is {item.name}')
item1 = item.id
break
But, just doing: item1 = items1[0]
Returns: TypeError: 'LimitOffsetBasedObjectCollection' object is not subscriptable
-
Hi!
query() method returns BoxObjectCollection object, which inherits from Iterator. Therefore you can use either next() method exposed by BoxObjectCollection class or next() method inherited form Iterator class. To get first item you can do:item1 = items1.next() # recommended
or
item1 = next(items1)
Regards
投稿コメントは受け付けていません。
コメント
1件のコメント