[stringtemplate-interest] PyST: first() and rest() don’t work on iterable non-lists

Roman Odaisky roma at qwertty.com
Mon Sep 8 02:03:04 PDT 2008


Hi,

Until someone points me to a PyST bugtracker, I’ll spam this list ;-)

In PyST 3.1, $first(something)$ and $rest(something)$ only work on built-in 
types. When I pass an iterable object, the functions seem to treat it as a 
whole. However, the template application operator does recognize them, so the 
result looks like this:

>>> st = StringTemplate(r'''$first(list):{<$it$>}$; $rest(list):{($it$)}$''')
>>> st["list"] = xrange(0, 5)
>>> print unicode(st)
<0><1><2><3><4>;

while I was expecting:

<0>; (1)(2)(3)(4)

Proper handling of iterable objects is very important. For example, in my case 
the objects are database result sets, and fetching them in bite-size portions 
is much more efficient than getting all the data into a Python list and 
passing it to ST, as I’m forced to do.

Perhaps it’s possible to return a generator from language.ASTExpr.rest?

-- 
WBR
Roman.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2286 bytes
Desc: not available
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20080908/d0fae341/attachment.bin 


More information about the stringtemplate-interest mailing list