Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '"this': 0.03; 'see:': 0.07; 'cc:addr:python-list': 0.11; 'python': 0.11; '"from': 0.16; 'from:addr:arskom.com.tr': 0.16; 'from:addr:burak.arslan': 0.16; 'from:name:burak arslan': 0.16; 'message-id:@arskom.com.tr': 0.16; 'received:arskomhosting.com': 0.16; 'scratch': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'quite': 0.32; 'something': 0.35; 'hi,': 0.36; 'generating': 0.39; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'world': 0.66; 'sample': 0.67; 'jul': 0.74; '2013,': 0.91 Date: Mon, 29 Jul 2013 15:14:48 +0300 From: Burak Arslan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130711 Thunderbird/17.0.7 MIME-Version: 1.0 To: Morten Guldager Subject: Re: Generating HTML References: In-Reply-To: X-Enigmail-Version: 1.5.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375100541 news.xs4all.nl 15900 [2001:888:2000:d::a6]:45285 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51440 Hi, On 07/29/13 14:41, Morten Guldager wrote: > Something like: > table_struct = ['table', ['tr', ['td', {class=>"red"}, "this is > red"],['td', {class=>"blue"}, "this is not red"]]] > html = struct2html(table_struct) > > Suggestions? > See: http://lxml.de/lxmlhtml.html#creating-html-with-the-e-factory Python 2.7.5 (default, Jul 16 2013, 00:38:32) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from lxml.html.builder import E >>> e = E.html( ... E.head( ... E.title("Sample Html Page") ... ), ... E.body( ... E.div( ... E.h1("Hello World"), ... E.p( ... "lxml is quite nice when it comes to generating HTML " ... "from scratch" ... ), ... id="container", ... ) ... ) ... ) >>> from lxml.html import tostring >>> print tostring(e, pretty_print=True) Sample Html Page

Hello World

lxml is quite nice when it comes to generating HTML from scratch