本文整理匯總了Python中six.Iterator方法的典型用法代碼示例。如果您正苦於以下問題:Python six.Iterator方法的具體用法?Python six.Iterator怎麽用?Python six.Iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類six
的用法示例。
在下文中一共展示了six.Iterator方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __next__
# 需要導入模塊: import six [as 別名]
# 或者: from six import Iterator [as 別名]
def __next__(self):
if self._done:
raise GraknError('Iterator was already iterated.')
try:
response = next(self._response_iterator)
except StopIteration:
raise GraknError('Internal client/protocol error,'
' did not receive an expected "done" or "iteratorId" message.'
'\n\n Please ensure client version is supported by server version.')
iter_res = response.iter_res
res_type = iter_res.WhichOneof('res')
if res_type == 'done':
self._done = True
raise StopIteration
elif res_type == 'iteratorId':
self._request_next_batch(iter_res.iteratorId)
return next(self)
else:
return self._resp_converter(iter_res)
示例2: is_iterator
# 需要導入模塊: import six [as 別名]
# 或者: from six import Iterator [as 別名]
def is_iterator(obj):
return isinstance(obj, collections.Iterator)
示例3: memorize
# 需要導入模塊: import six [as 別名]
# 或者: from six import Iterator [as 別名]
def memorize(collection, engine):
if not is_iterator(collection):
return collection
yielded = []
class RememberingIterator(six.Iterator):
def __init__(self):
self.seq = iter(collection)
self.index = 0
def __iter__(self):
return RememberingIterator()
def __next__(self):
if self.index < len(yielded):
self.index += 1
return yielded[self.index - 1]
else:
val = next(self.seq)
yielded.append(val)
limit_memory_usage(engine, (1, yielded))
self.index += 1
return val
return RememberingIterator()
示例4: query
# 需要導入模塊: import six [as 別名]
# 或者: from six import Iterator [as 別名]
def query(self, query, infer, explain, batch_size):
return Iterator(self._communicator,
RequestBuilder.start_iterating_query(query, infer, explain, batch_size),
ResponseReader.ResponseReader.get_query_results(self))
示例5: get_attributes_by_value
# 需要導入模塊: import six [as 別名]
# 或者: from six import Iterator [as 別名]
def get_attributes_by_value(self, attribute_value, value_type):
request = RequestBuilder.start_iterating_get_attributes_by_value(attribute_value, value_type)
return Iterator(self._communicator, request, ResponseReader.ResponseReader.get_attributes_by_value(self))
示例6: run_concept_iter_method
# 需要導入模塊: import six [as 別名]
# 或者: from six import Iterator [as 別名]
def run_concept_iter_method(self, concept_id, grpc_concept_iter_method_req):
return Iterator(self._communicator,
RequestBuilder.start_iterating_concept_method(concept_id, grpc_concept_iter_method_req),
lambda res: res.conceptMethod_iter_res.response)
示例7: test_iterator
# 需要導入模塊: import six [as 別名]
# 或者: from six import Iterator [as 別名]
def test_iterator():
class myiter(six.Iterator):
def __next__(self):
return 13
assert six.advance_iterator(myiter()) == 13
class myitersub(myiter):
def __next__(self):
return 14
assert six.advance_iterator(myitersub()) == 14