[lxml-dev] Question about lxml.html.builder

I'm using Python 2.5.2 with lxml 2.1.1-1ubuntu1. I'm trying to get some version of the lines involving 'wp_ps' to work: if opts.text: wp_ps = [E.P(p) for p in bio.wp_text.split('\n')] table.append( E.TR( E.TD(''), E.TD().extend(wp_ps), #E.TD(bio.wp_text, colspan='2'), E.TD(bio.eb_text, colspan='2'), valign="top", ), ) Simply, I want to take text with LFs and turn them into Ps.

Joseph Reagle wrote:
You didn't mention what isn't working here and how it isn't working the way you expect. Anyway, without testing, I'd write it this way: table.append( E.TR( E.TD(''), E.TD(*[E.P(p) for p in bio.wp_text.split('\n')]), #E.TD(bio.wp_text, colspan='2'), E.TD(bio.eb_text, colspan='2'), valign="top", ), ) Stefan

On Thursday 01 October 2009, Stefan Behnel wrote:
E.TD(*[E.P(p) for p in bio.wp_text.split('\n')]),
Thanks, that does the trick: you're using *args syntax to "delist" the list and make them arguments? Also, when I want to add a valign, I note it has to be: E.TD(colspan='2', *[E.P(p) for p in bio.wp_text.split('\n')]), not E.TD(*[E.P(p) for p in bio.wp_text.split('\n')], colspan='2'), though I'm not sure why.

Joseph Reagle wrote:
You didn't mention what isn't working here and how it isn't working the way you expect. Anyway, without testing, I'd write it this way: table.append( E.TR( E.TD(''), E.TD(*[E.P(p) for p in bio.wp_text.split('\n')]), #E.TD(bio.wp_text, colspan='2'), E.TD(bio.eb_text, colspan='2'), valign="top", ), ) Stefan

On Thursday 01 October 2009, Stefan Behnel wrote:
E.TD(*[E.P(p) for p in bio.wp_text.split('\n')]),
Thanks, that does the trick: you're using *args syntax to "delist" the list and make them arguments? Also, when I want to add a valign, I note it has to be: E.TD(colspan='2', *[E.P(p) for p in bio.wp_text.split('\n')]), not E.TD(*[E.P(p) for p in bio.wp_text.split('\n')], colspan='2'), though I'm not sure why.
participants (2)
-
Joseph Reagle
-
Stefan Behnel