[Checkins] SVN: z3c.batching/trunk/src/z3c/batching/README.txt Replaced literal block with doctest blocks
Christophe Combelles
ccomb at free.fr
Sun Oct 12 06:53:55 EDT 2008
Log message for revision 92072:
Replaced literal block with doctest blocks
Changed:
U z3c.batching/trunk/src/z3c/batching/README.txt
-=-
Modified: z3c.batching/trunk/src/z3c/batching/README.txt
===================================================================
--- z3c.batching/trunk/src/z3c/batching/README.txt 2008-10-12 10:52:49 UTC (rev 92071)
+++ z3c.batching/trunk/src/z3c/batching/README.txt 2008-10-12 10:53:55 UTC (rev 92072)
@@ -8,7 +8,7 @@
large sequence into smaller batches. Let's start by creating a simple list,
which will be our full sequence:
-Batch on empty root::
+Batch on empty root:
>>> from z3c.batching.batch import Batch
>>> batch = Batch([], size=3)
@@ -39,24 +39,24 @@
>>> sequence = ['one', 'two', 'three', 'four', 'five', 'six', 'seven',
... 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen']
-We can now create a batch for this sequence. Let's make our batch size 3::
+We can now create a batch for this sequence. Let's make our batch size 3:
>>> batch = Batch(sequence, size=3)
The first argument to the batch is always the full sequence. If no start
-element is specified, the batch starts at the first element::
+element is specified, the batch starts at the first element:
>>> list(batch)
['one', 'two', 'three']
-The start index is commonly specified in the constructor though::
+The start index is commonly specified in the constructor though:
>>> batch = Batch(sequence, start=6, size=3)
>>> list(batch)
['seven', 'eight', 'nine']
Note that the start is an index and starts at zero. If the start index is
-greater than the largest index of the sequence, an index error is raised::
+greater than the largest index of the sequence, an index error is raised:
>>> Batch(sequence, start=15, size=3)
Traceback (most recent call last):
@@ -64,18 +64,18 @@
IndexError: start index key out of range
A batch implements the finite sequence interface and thus supports some
-standard methods. For example, you can ask the batch for its length::
+standard methods. For example, you can ask the batch for its length:
>>> len(batch)
3
Note that the length returns the true size of the batch, not the size we asked
-for::
+for:
>>> len(Batch(sequence, start=12, size=3))
1
-You can also get an element by index, which is relative to the batch::
+You can also get an element by index, which is relative to the batch:
>>> batch[0]
'seven'
@@ -84,7 +84,7 @@
>>> batch[2]
'nine'
-Slicing::
+Slicing:
>>> batch[:1]
['seven']
@@ -102,14 +102,14 @@
[]
-If you ask for index that is out of range, an index error is raised::
+If you ask for index that is out of range, an index error is raised:
>>> batch[3]
Traceback (most recent call last):
...
IndexError: batch index out of range
-You can also iterate through the batch::
+You can also iterate through the batch:
>>> iterator = iter(batch)
>>> iterator.next()
@@ -119,7 +119,7 @@
>>> iterator.next()
'nine'
-Batch also implement some of IReadSequence interface::
+Batch also implement some of IReadSequence interface:
>>> 'eight' in batch
True
@@ -137,48 +137,48 @@
True
Besides all of those common API methods, there are several properties that were
-designed to make your life simpler. The start and size are specified::
+designed to make your life simpler. The start and size are specified:
>>> batch.start
6
>>> batch.size
3
-The end index of the batch is immediately computed::
+The end index of the batch is immediately computed:
>>> batch.end
8
The UI often requires that the number of the batch and the total number of
-batches is computed::
+batches is computed:
>>> batch.number
3
>>> batch.total
5
-You can also ask for the next batch::
+You can also ask for the next batch:
>>> batch.next
<Batch start=9, size=3>
-If the current batch is the last one, the next batch is None::
+If the current batch is the last one, the next batch is None:
>>> Batch(sequence, start=12, size=3).next is None
True
-The previous batch shows the previous batch::
+The previous batch shows the previous batch:
>>> batch.previous
<Batch start=3, size=3>
-If the current batch is the first one, the previous batch is None::
+If the current batch is the first one, the previous batch is None:
>>> Batch(sequence, start=0, size=3).previous is None
True
The final two properties deal with the elements within the batch. They ask for
-the first and last element of the batch::
+the first and last element of the batch:
>>> batch.firstElement
'seven'
@@ -187,13 +187,13 @@
'nine'
-Total batches::
+Total batches:
>>> batch = Batch(sequence[:-1], size=3)
>>> batch.total
4
-We can have access to all batches::
+We can have access to all batches:
>>> len(batch.batches)
4
@@ -215,7 +215,7 @@
>>> batch.batches[-2]
<Batch start=6, size=3>
-Slicing::
+Slicing:
>>> batch.batches[:1]
[<Batch start=0, size=3>]
@@ -242,12 +242,12 @@
we want to display only a subset of all the batches.
A helper function is provided for that purpose:
-First build a large sequence of batches (or anything else)::
+First build a large sequence of batches (or anything else):
>>> batches = range(100)
Then extract only the first and last items, as well as the neighbourhood of the
-46th item (index = 45). We want 3 neighbours at the left, 5 at the right::
+46th item (index = 45). We want 3 neighbours at the left, 5 at the right:
>>> from z3c.batching.batch import first_neighbours_last
>>> first_neighbours_last(batches, 45, 3, 5)
More information about the Checkins
mailing list