4 ms·
> I find p very natural because I think "print" every time ... I can do everything I need to do, plus it is obvious how to do it Probably more because you've u
by anthonyb 16y ago
> I find p very natural because I think "print" every time ... I can do everything I need to do, plus it is obvious how to do it
Probably more because you've used it for a while. I generally prefer longer variable names to help with readability, which makes the accumulator/with technique more verbose and harder to read.
If you don't like import * , you can use a combination of from ...lib.html import p, h1, h2 and from ...lib import html, but as long as your namespace is clean (ie. use __all__) and you're clear that the module is designed to be imported that way, I don't see that it's a huge issue, particularly if it clears up a lot of clutter.
There's also nothing in that API that prevents you looping, or assigning helper variables - you just store local variables before you generate your template or create sections of your template a bit at a time. Or use list/generator comprehensions, which would fit the functional paradigm a bit better. A couple of examples:
ul( *[li(option.name) for option in options], style="dropdown", ...)
def index_page(request):
my_name = reqest.GET.get('name', 'Bob')
head = html.head( title('Hello, %s' % my_name))
body = html.body( h1('...'), p('..'))
return html.html(head, body)
Of course, all of this is developed using the POOMA methodology, so there might be some hideous limitation, but I can't see any from a few minutes thought.