The following fails to run with "NameError: name 'printComments' is not defined", but the outputted python code looks fine.
<?py
def printComments(lst, depth):
for d in lst:
?>
<div class="children">
<?py printComments(d['children'], depth+1) ?>
</div>
<?py #endfor ?>
<?py #enddef ?>
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Tenjin-1.1.1-py2.6.egg/tenjin.py", line 991, in render
exec(self.bytecode, globals, locals)