473,732 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating HTML from python

Hi,

I wish to use an easy way to generate reports from wxPython and feel
wxHtmlEasyPrint ing could be a good solution.

I now need to generate the HTML wxHtmlEasyPrint ing can print: I need to have
a title followed by lines of text that do not look too ugly. If possible I
would like to use an existing module.

Q1) Is there such a module ?
Q2) Is my approach fairly good ?

Regards,

Philippe

Jul 19 '05 #1
14 2598
PS: I am looking at the formatter module which seems to be related to HTML
somehow, but without any code sample I'm a bit lost
Philippe C. Martin wrote:
Hi,

I wish to use an easy way to generate reports from wxPython and feel
wxHtmlEasyPrint ing could be a good solution.

I now need to generate the HTML wxHtmlEasyPrint ing can print: I need to
have a title followed by lines of text that do not look too ugly. If
possible I would like to use an existing module.

Q1) Is there such a module ?
Q2) Is my approach fairly good ?

Regards,

Philippe


Jul 19 '05 #2
You could generate your report in reStructuredTex t
format (Google is your friend) and then convert
them in HTML, PS, PDF, etc.

Michele Simionato

Jul 19 '05 #3
Am Thu, 09 Jun 2005 12:43:19 +0000 schrieb Philippe C. Martin:
Hi,

I wish to use an easy way to generate reports from wxPython and feel
wxHtmlEasyPrint ing could be a good solution.

I now need to generate the HTML wxHtmlEasyPrint ing can print


I don't know wxPython, but generating HTML is very easy.

Some people say mixing HTML and programming code is not good.

But if you want to create dynamic pages with more logic than HTML
this is the best solution.

Example: Multiplication Table

rows=[]
heading=[]
for i in range(1, 11):
heading.append( '<th bgcolor="grey"> %s</th>' % i)
cols=[]
for j in range(1, 11):
cols.append('<t d align="right">% s</td>' % (i*j))
row='<tr><th bgcolor="grey"> %s</th>%s</tr>' % (i, ''.join(cols))
rows.append(row )
html="""
<html>
<head><title>Mu ltiplication Table</title></head>
<body>
<table border="1">
<tr>
<th>&nbsp;</th> %s
</tr>
%s
</table>
</body>
</html> """ % (''.join(headin g), ''.join(rows))

I guess this looks more ugly in most template languages.

HTH,
Thomas

--
Thomas Güttler, http://www.thomas-guettler.de/
Jul 19 '05 #4
I'll take a pick thanks - I like the fact it's buit-in (no extra
installation)

Michele Simionato wrote:
You could generate your report in reStructuredTex t
format (Google is your friend) and then convert
them in HTML, PS, PDF, etc.

Michele Simionato


Jul 19 '05 #5
Thanks a bunch,

I'm currently playing with HTMLGen (great but not in Python distrib ...) and
it look very good - Yet your code example looks simple enough for me to
look at that alternative.


Thomas Guettler wrote:
Am Thu, 09 Jun 2005 12:43:19 +0000 schrieb Philippe C. Martin:
Hi,

I wish to use an easy way to generate reports from wxPython and feel
wxHtmlEasyPrint ing could be a good solution.

I now need to generate the HTML wxHtmlEasyPrint ing can print


I don't know wxPython, but generating HTML is very easy.

Some people say mixing HTML and programming code is not good.

But if you want to create dynamic pages with more logic than HTML
this is the best solution.

Example: Multiplication Table

rows=[]
heading=[]
for i in range(1, 11):
heading.append( '<th bgcolor="grey"> %s</th>' % i)
cols=[]
for j in range(1, 11):
cols.append('<t d align="right">% s</td>' % (i*j))
row='<tr><th bgcolor="grey"> %s</th>%s</tr>' % (i, ''.join(cols))
rows.append(row )
html="""
<html>
<head><title>Mu ltiplication Table</title></head>
<body>
<table border="1">
<tr>
<th>&nbsp;</th> %s
</tr>
%s
</table>
</body>
</html> """ % (''.join(headin g), ''.join(rows))

I guess this looks more ugly in most template languages.

HTH,
Thomas


Jul 19 '05 #6

I looked at HTMLGen a while ago- I didn't see what the advantage was.
I wrote soem code similar to the example above, to generate a page..
It worked out fine.

However, I want to add HTML ouput to many of my other python programs,
and I don't want to re-write this for each program. So some higher
level of abastraction is needed, but I don't know how just yet.

HTMLGen is no longer maintained, so I don't know what the best choice
is.

If you know the basics of HTMl, you can write a simple class to write
the html, and just call a method from your program, so your app does
not have any HTML in it.
Philippe C. Martin wrote:
Thanks a bunch,

I'm currently playing with HTMLGen (great but not in Python distrib ...) and
it look very good - Yet your code example looks simple enough for me to
look at that alternative.


Thomas Guettler wrote:
Am Thu, 09 Jun 2005 12:43:19 +0000 schrieb Philippe C. Martin:
Hi,

I wish to use an easy way to generate reports from wxPython and feel
wxHtmlEasyPrint ing could be a good solution.

I now need to generate the HTML wxHtmlEasyPrint ing can print


I don't know wxPython, but generating HTML is very easy.

Some people say mixing HTML and programming code is not good.

But if you want to create dynamic pages with more logic than HTML
this is the best solution.

Example: Multiplication Table

rows=[]
heading=[]
for i in range(1, 11):
heading.append( '<th bgcolor="grey"> %s</th>' % i)
cols=[]
for j in range(1, 11):
cols.append('<t d align="right">% s</td>' % (i*j))
row='<tr><th bgcolor="grey"> %s</th>%s</tr>' % (i, ''.join(cols))
rows.append(row )
html="""
<html>
<head><title>Mu ltiplication Table</title></head>
<body>
<table border="1">
<tr>
<th>&nbsp;</th> %s
</tr>
%s
</table>
</body>
</html> """ % (''.join(headin g), ''.join(rows))

I guess this looks more ugly in most template languages.

HTH,
Thomas


Jul 19 '05 #7
Philippe C. Martin wrote:
Hi,

I wish to use an easy way to generate reports from wxPython and feel
wxHtmlEasyPrint ing could be a good solution.

I now need to generate the HTML wxHtmlEasyPrint ing can print: I need to have
a title followed by lines of text that do not look too ugly. If possible I
would like to use an existing module.

Q1) Is there such a module ?
Q2) Is my approach fairly good ?


There are many ways to do this. The simplest is just to mix HTML and Python code in your own module, as Thomas has shown. This is quick and easy to do but IMO it doesn't scale well to large pages or large number of pages; the mix of raw HTML and Python code is hard to work with.

This page lists many alternatives: http://wiki.python.org/moin/WebProgramming

The interesting categories from that page:
"Templating Engines" provide a way to describe the HTML that is more-or-less independent of the code. They vary widely in style. If you want a lot of control over the generated HTML you probably want to use one of these.

"HTML Shorthand Processors" provide an alternate way to specify markup and a program to convert the markup to HTML. reStructuredTex t is in this category. To use one of these you would still have to generate the alternate markup in your program similar to the simple HTML method.

"HTML Generation class libraries" are libraries that make it easier to create HTML programmaticall y. This can be a good approach if the HTML is simple. I guess you can add many Python XML libraries to this category as well; for example you could use ElementTree to generate a model of an XHTML page and output it.

Choosing within the categories depends a lot on personal preference, you just have to find a package whose style you like and whose features fit your needs.

HTH,
Kent
Jul 19 '05 #8
Thanks

Kent Johnson wrote:
Philippe C. Martin wrote:
Hi,

I wish to use an easy way to generate reports from wxPython and feel
wxHtmlEasyPrint ing could be a good solution.

I now need to generate the HTML wxHtmlEasyPrint ing can print: I need to
have a title followed by lines of text that do not look too ugly. If
possible I would like to use an existing module.

Q1) Is there such a module ?
Q2) Is my approach fairly good ?


There are many ways to do this. The simplest is just to mix HTML and
Python code in your own module, as Thomas has shown. This is quick and
easy to do but IMO it doesn't scale well to large pages or large number of
pages; the mix of raw HTML and Python code is hard to work with.

This page lists many alternatives:
http://wiki.python.org/moin/WebProgramming

The interesting categories from that page:
"Templating Engines" provide a way to describe the HTML that is
more-or-less independent of the code. They vary widely in style. If you
want a lot of control over the generated HTML you probably want to use one
of these.

"HTML Shorthand Processors" provide an alternate way to specify markup and
a program to convert the markup to HTML. reStructuredTex t is in this
category. To use one of these you would still have to generate the
alternate markup in your program similar to the simple HTML method.

"HTML Generation class libraries" are libraries that make it easier to
create HTML programmaticall y. This can be a good approach if the HTML is
simple. I guess you can add many Python XML libraries to this category as
well; for example you could use ElementTree to generate a model of an
XHTML page and output it.

Choosing within the categories depends a lot on personal preference, you
just have to find a package whose style you like and whose features fit
your needs.

HTH,
Kent


Jul 19 '05 #9
Cappy2112 wrote:
I looked at HTMLGen a while ago- I didn't see what the advantage was.
I wrote soem code similar to the example above, to generate a page..
It worked out fine.

However, I want to add HTML ouput to many of my other python programs,
and I don't want to re-write this for each program. So some higher
level of abastraction is needed, but I don't know how just yet.

HTMLGen is no longer maintained, so I don't know what the best choice
is.


If you want an alternative to HTMLGen that is still maintained, you
might want to try XIST (http://www.livinglogic.de/Python/xist)

A few simple examples can be found here:
http://www.livinglogic.de/Python/xist/Examples.html

Bye,
Walter Dörwald
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1904
by: Dan Gass | last post by:
The difflib.py module and the diff.py tools script in Python 2.4 alpha 3 now support generating side by side (with intra line differences) in HTML format. I have found this useful for performing build release comparisons (I use a script to generate a main page showing all the files that were changed in a build with hyperlinks to side by side differences for each of those files). I also find it useful for generating HTML test reports to...
13
4645
by: Tim Henderson | last post by:
Hi I want to dynamically generate a graph in python that would be displayable on a web page. What would be the best way to do this? The reason I want to do this, is because I am making a program to convert data from scientic probes into web pages. I have been able to do every thing except the graph generation. Your help would be much appriciated
8
4257
by: Tim Daneliuk | last post by:
I use a makefile to create distribution tarballs of freestanding Python programs and their documentation. I cannot seem to find the right command line option to just generate a pyc/pyo file from the program and then exit. If I use 'python -OOOO -c"import myprog"' it creates the pyo file, but myprog starts up and keeps running. IOW, I need a batch method for generating compiled python. I know it exists, but I can't find it for some...
0
1789
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return dict() print combo2(5)
13
2393
by: Michele Simionato | last post by:
What is the recommended way of generating HTML from Python? I know of HTMLGen and of few recipes in the Cookbook, but is there something which is more or less standard? Also, are there plans to include a module for HTML generation in the standard library? I really would like to see some standardization in this area. Michele Simionato
4
6015
by: Andreas Jung | last post by:
Hi, does anyone know of a high-level solution to produce RTF from Python (something similar to Reportlab for producing PDF)? Thanks, Andreas -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (Darwin)
17
2135
by: flupke | last post by:
Hi, i create my GUIs mainly via wxGlade. However when you start of to program and want to do some rearranging to the gui, wxglade overwrites your file and you've got to put your own code back in. I think i can work around that (at least a bit) by making a second file that imports the gui generated by wxglade and make classes that extend the original ones. For instance i could have a class MainForm that extends the wxFrame
1
3232
by: Xah Lee | last post by:
The following is a program to generate thumbnail images for a website. Useful, if you want to do that. It is used to generate the thumbnails for my “Banners, Damsels, and Mores†project gallery. ( http://xahlee.org/Periodic_dosage_dir/lanci/lanci.html ) Comments and versions in other lang welcome. Xah
3
1302
by: Sebastian Bassi | last post by:
Hello, What are people using these days to generate HTML? I still use HTMLgen, but I want to know if there are new options. I don't want/need a web-framework a la Zope, just want to produce valid HTML from Python. Best, SB. --
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.