tags:

views:

112

answers:

3

I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures.

I really don't think writing to a file manually is the best method, and the code may be very long. So is there a better way to do this, possibly html specific?

+3  A: 

Use a templating engine such as Genshi or Jinja2.

Ignacio Vazquez-Abrams
+3  A: 

I think, if i understand you correct, you can see here.

ghostdog74
A: 

Templating, as suggested in other answers, is probably the best answer (I wrote an early, quirky templating module called yaptu, but modern mature ones as suggested in other answers will probably make you happier;-).

However, though it's been a long time since I last used it, I fondly recall the Quixote approach, which is roughly a "reverse templating" (embedding HTML generation within Python, rather than viceversa as normal templating does). Maybe you should take a look and see if you like it better;-).

Alex Martelli