Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

From Python it is required to output a text report with multiple sections and contents such as simple paragraphs, lists, tables, etc. created from basic Python data structures.

Is there a "standard" Python way to create such a simple text report, beside doing string formatting from the ground up.

It would be nice if a HTML report could also be generated, but the primary output is to be text, and more advanced reports line PDF and XML are unnecessary.

share|improve this question

closed as too broad by delnan, Junuxx, matino, Ian, Siddharth Jul 8 '13 at 14:29

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

This sort of question is best investigated using a search engine because those answering cannot know all your requirements. You'll have to research the different options. Here is where I would start...

  1. Generate PDF reports using Report Lab, or see reportlab at pypi.
  2. Create HTML reports using a template engine like jinja2. Search for others because there might be something you like better. Mustache is nice for logic-less templates.
  3. Create text reports using Python's built in open and file.write. Maybe see pod too.
  4. Generate CSV files using Python's csv module.
share|improve this answer

Two approaches that you could take:

You could use a templating engine; for each report, provide two templates - one that generates html and one that generates plain text. Lots of customisability, but every time you make a change to the report you're going to have to change both templates.

The alternative is to make use of a markup format that's designed to be converted into several formats. As an example, the reStructuredText format is designed to be human-readable as plain text, but also easy to convert into HTML (or latex, or pdf, or ...) and produce good-looking well laid-out documents.

The latter is how Python's documentation is written - it's written in rST and converted into HTML and other formats via Sphinx. You can see the raw text for any page of the Python docs by clicking the "Show Source" link - for instance, http://docs.python.org/3/_sources/library/constants.txt is the source for http://docs.python.org/3/library/constants.html#constants-added-by-the-site-module

You might still need to use a template engine to generate the rST form of your report, but hopefully that gives you a plain-text version immediately, and then that plain-text version can be processed to give HTML and whatever other rich formats you need. This way, you'd only need to write one template, but that one template would be able to produce reports in many formats.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.