473,761 Members | 9,379 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
14 2600
"Philippe C. Martin" <ph******@phili ppecmartin.com> writes:
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

As others have noted, if you need any computation at all, it is easier
to write directly in python.

I came to python from perl, where I used CGI.pm. To get that effect,
I wrote my own CGIpm.py and used it for a while.
http://www.seanet.com/~hgg9140/comp/index.html

But (at the suggestion of others in this newsgroup), I then tried
writing directly. The net effect is trivial html generation, with all
the power of python at your fingertips.

Note:
To save even more time, I made a CGI template that includes this main:

#============== ==============
if __name__=="__ma in__":
mystart()
#cgi.print_envi ron_usage()
#cgi.print_envi ron()
form = cgi.FieldStorag e()
try:
if len(form)==0:
send_form1()
else:
form_name=form['form_name'].value
if form_name=='for m1':
recv_form1()
except StandardError, e:
print "\n<BR>ERRO R: %s\n" % e
myend()

To support a stateless world:

1. Each form has a send_xyz and recv_xyz function. The end of each
recv_xyz decides what send_xyz to do next.

2. mystart and myend handle opening and closing the http and html.
They also handle state save/restore as needed (pickle or database).


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


--
ha************@ boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
Jul 19 '05 #11
Thanks
Walter Dörwald wrote:
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 #12
PS: Just wanted to add that HTMLGen works very well and outputs html that
wxHtmlEasyPrint ing and my email client have not problem reading (I output
student grades, missing assignments, ... in tables).

The one gitch is they do not have any installation program (that I've seen)
for windows.

Regards,

Philippe


Walter Dörwald wrote:
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 #13

"Philippe C. Martin" <ph******@phili ppecmartin.com> wrote in message news:HP******** ********@newssv r12.news.prodig y.com...
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 is one huge problem with wxHtml and consequently wxHtmlEasyPrint ing. It
doesn't understand stylesheets in any way. There are many packages that
generate HTML, but they all expect a lot of the styling to be handled by
CSS. It is also a lot easier to write that way.

I would absolutely love a piece of code that could take CSS and HTML and
apply the CSS to the HTML to get the right appearance, but without any
CSS left. For example it would turn CSS formatting for class/div/span
into HTML attributes, as well as overal formatting instructions.

I did do something similar for BitPim but it requires the HTML to be perfect
and the CSS is actually a Python data structure expressing the attributes and
how they get applied. I'd love to replace it with something better.

But ultimately it does work.

Roger

Jul 19 '05 #14
Philippe C. Martin wrote:
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.


How to do this really depends on what your data looks like, and how you
get it. E.g. if you just want uniform pages with paragraphs of plain
texts with headings in between, you can just make a template HTML file
with the main block of text replaced with %s, and then do something like:

text = []

for heading, paragraph in data_source:
text.append('<h 2>%s</h2>' % heading)
text.append(par agraph)

templ = open('template. html').read()
print templ % '\n'.join(text)
If your data has more structure, you might find a tool like Fredrik
Lundh's elementtree useful.
Jul 19 '05 #15

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

Similar topics

0
1905
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
4648
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
4258
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
1791
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
6016
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
2138
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
3233
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
1304
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
9522
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9902
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
6603
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
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.