On Tuesday, June 28, 2011 9:43:35 AM UTC-4, Anthony wrote:
>
> HTML helper objects do not support the + operator (they don't have an
> __add__ method). Your example works because you are concatenating an HTML
> helper object with an XML object, and the XML object does support the +
> operator -- it does so by calling the __str__ method of both objects and
> concatenating the strings (via Python's string formatting syntax). If you
> replace var2 with TD("bbbb"), you'll get a syntax error instead of a string
> returned.
> If you want to concatenate two (or more) helper objects together without
> putting them inside another helper object and without first converting them
> to strings, you can put them inside an empty TAG object:
> TAG[''](var1, var2)
>
The nameless tag is a helpful trick, so I went ahead and added a note about
it in the book near the end of the section explaining TAG:
http://web2py.com/book/default/chapter/05#Custom-Helpers.
Anthony