One Python helper I find enormously useful is "extend()" as applied to list
objects. Extend differs from append in that it adds the items of the list
provided at the same level as the current list items, thereby "extending"
the list.
An example:
body = DIV("this","is","the","body")
Result: a DIV with four elements in it.
body.append(["and","additional","elements"])
Result: Not what you wanted! It appends a list to the original DIV making
a mess.
body.extend(["and","additional","elements"])
This is what you wanted:
DIV("this","is","the","body","and","additional","elements")
I've been monkey-patching "extend" into DIV quite awhile now and thought
you may want to consider adding it to the DIV helper. Here is my
monkey-patch:
def extend(self,coll):
self._setnode(coll)
ret = self.components.extend(coll)
self._fixup()
return ret
DIV.extend = extend
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.