views:

147

answers:

1

Hi there

I'm using lxml to programatically build HTML and I need to include a custom comment in the output. Whilst there is code in lxml to cope with comments (they can be instantiated when parsing existing HTML code) I cannot find a way to instantiate one programatically.

Can anyone help?

+2  A: 

You can use the lxml.etree.Comment() factory function. It will return a comment element that you can use like any other element.

Steef
Man! I tried this a load of times I swear! It was crashing lxml before but now it seems to be working. Thanks for the confirmation that it should work.
jkp