How to Generate dynamic HTML Report using Python

Ned Batchelder ned at nedbatchelder.com
Sun Nov 19 21:44:07 EST 2017


On 11/19/17 8:40 PM, Stefan Ram wrote:
> mradul dhakad <mradul.k.dhakad at gmail.com> writes:
>> I am new to python . I am trying to generate Dynamic HTML report using
>> Pyhton based on number of rows selected from query .Do any one can suggest
>> some thing for it.
>    main.py
>
> import sqlite3
> conn = sqlite3.connect( ':memory:' )
> c = conn.cursor()
> c.execute( "CREATE TABLE T ( A TEXT )" )
> c.execute( "INSERT INTO T ( A ) VALUES ( '1' ), ( '2' )" )
> conn.commit()
> c.execute( "SELECT * FROM T WHERE A = '1'" )
> number_of_rows_selected_from_query = len( c.fetchall() )
> conn.close()
> del c
> del conn
> del sqlite3

I'm curious what superstition compels you to delete these names? There's 
no need to.

Also, why set headers that prevent the Python-List mailing list from 
archiving your messages?

--Ned.

> def HTML( x ):
>      return f'''<!DOCTYPE html>
>      <html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">
>      <head><meta charset="UTF-8" />
>      <title>Number Of Rows Selected From Query</title><style type="text/css">
>      </style></head><body><h1>Number Of Rows Selected From Query</h1>
>      <p>The number of rows selected from query is {x}.</p></body></html>'''
>
> print( HTML( number_of_rows_selected_from_query ))
>
>    transcript
>
>      <!DOCTYPE html>
>      <html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">
>      <head><meta charset="UTF-8" />
>      <title>Number Of Rows Selected From Query</title><style type="text/css">
>      </style></head><body><h1>Number Of Rows Selected From Query</h1>
>      <p>The number of rows selected from query is 1.</p></body></html>
>




More information about the Python-list mailing list