Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 964 Bytes

each.md

File metadata and controls

46 lines (35 loc) · 964 Bytes
layout api-command
language Python
permalink api/python/each/
command for
related_commands
next list close (cursor)
next/
to_array/
close-cursor/

Command syntax

{% apibody %} for items in cursor: for items in array: for items in feed: {% endapibody %}

Description

Lazily iterate over a result set one element at a time.

RethinkDB sequences can be iterated through via the Python Iterable interface; use standard Python commands like for loops to access each item in the sequence.

Example: Let's process all the elements!

cursor = r.table('users').run(conn)
for doc in cursor:
    process_row(doc)

Example: Stop the iteration prematurely and close the connection manually.

cursor = r.table('users').run(conn)
for doc in cursor:
    ok = process_row(doc)
    if ok is False:
        cursor.close()
        break