- Plate.traverse(batch_size: int, direction: Literal['up', 'down', 'right', 'left', 'snake_up', 'snake_down', 'snake_left', 'snake_right'], repeat: bool = False) Generator[List[T], None, None] #
Traverse the items in this resource.
"snake_right"start at the top left item (A1). Directions
"snake_up"start at the bottom left (H1). Directions
"snake_left"start at the top right (A12).
The snake directions alternate between going in the given direction and going in the opposite direction. For example,
"snake_down"will go from A1 to H1, then H2 to A2, then A3 to H3, etc.
repeat=False, if the batch size does not divide the number of items evenly, the last batch will be smaller than the others. With
repeat=True, the batch would contain the same number of items, and batch would be padded with items from the beginning of the resource. For example, if the resource has 96 items and the batch size is 5, the first batch would be
[A1, B1, C1, D1, E1], the 20th batch would be
[H12, A1, B1, C1, D1], and the 21st batch would be
[E1, F1, G1, H1, A2].
batch_size (int) – The number of items to return in each batch.
direction (Literal['up', 'down', 'right', 'left', 'snake_up', 'snake_down', 'snake_left', 'snake_right']) – The direction to traverse the items. Can be one of “up”, “down”, “right”, “left”, “snake_up”, “snake_down”, “snake_left” or “snake_right”.
repeat (bool) – Whether to repeat the traversal when the end of the resource is reached.
A list of items.
ValueError – If the direction is not valid.
- Return type:
Traverse the items in the resource from top to bottom, in batches of 3:
>>> items.traverse(batch_size=3, direction="down", repeat=False)
[[<Item A1>, <Item B1>, <Item C1>], [<Item D1>, <Item E1>, <Item F1>], …]
Traverse the items in the resource from left to right, in batches of 5, repeating the traversal when the end of the resource is reached:
>>> items.traverse(batch_size=5, direction="right", repeat=True)
[[<Item A1>, <Item A2>, <Item A3>], [<Item A4>, <Item A5>, <Item A6>], …]