[Zope] Checking sequence-index using dtml-if
Curtis Maloney
curtis@cardgate.net
Wed, 21 Feb 2001 14:52:49 +1100
On Wednesday 21 February 2001 14:02, Jeff Hotz wrote:
> Thanks.
>
> Could you please help me understand the syntax of the statement you
> suggested?
>
> Specifically, this portion ZSQLMethod()[:3]
>
> Additionally, with this method, is there a way to process all records
> starting with a certain number until eof()?
>
OK. Starting with the line:
<dtml-in expr="an_sql_method()[:3]">
(this is exactly the same as <dtml-in "an_sql_method()[:3]"> but is more
clear to the human that it's an expression.)
The dtml-in portion, as you know, means "iterate over the elements in this
list".
expr="" means 'evaluate this string as Python'
an_sql_method() is fairly obvious... and since it returns a List, you can
'slice' the list, using [:3], which means "the first 3 elements".
If you wanted to start with the fourth, and continue on, you would use:
an_sql_method()[4:]
Note, this is not the same as:
an_sql_method()[4]
which would return ONLY the fourth element. This is standard Python syntax,
which is fairly clearly documented in the Python language documentation.
> Thanks again for your help.
>
Have a better one,
Curtis Maloney.