Bookmark and Share

One of the things that I face regularly is report generation. Often they’re free form, by which I mean not tables full of tabulated data.

Output from my htmlAnsii() class

Output from my .htmlAnsii() class

Just "is this ok, is that ok, 27 of the other happened", that sort of thing. I like to use color -- green if everything is ok, red if it isn't and so on.

I'm often out where I want the report in a web browser. But then again, I'm often at my desk, signed in to a console and I want it there. The environments couldn't be much more different; HTML tags on the one hand, within the wrapper of a page, and ANSII escape sequences on the other. And they're both kind of annoying and error-prone to write out explicitly, especially when you're doing it a lot.

What to do?

This generated the output in the image at the top of the page.

This generated the output in the image at the top of the page.

Well, like any truly sane person, I tend to write my script-y stuff in Python. So what was called for was an import library that would make all the pain go away. And here is the latest version:

If you are interested in this class, as of April 2015 it is still under active development. Until (at least) the end of May it will very likely be useful to check back regularly for updates.

To see some of what .htmlAnsii() and .dumpDicts() can do, just execute the import library directly:

==> python 

The examples you'll see run are in the import library at the end. I show you how to use it in various ways. Enjoy!


Revision Changes
1.0.4 / 1.0.4 Fixed a bug with the utility method .d() in html mode that prevented it from working in some cases. Sorry. Sigh.
1.0.4 / 1.0.3 New .dumpDicts() optional control flags: nototal, limit
New .dumpDicts() optional interspersing text inter for negative limit case
New .commaSep() utility in .dumpDicts()for comma-separated integers
New .fmtTime() utility in .dumpDicts() for printing out seconds as durations
New .dumpDicts() optional parameters: title, trailer for leading and trialing strings
1.0.4 / 1.0.2 Fixed a bug with optional nsort parameter in .dumpDicts() that prevented it from working. Sorry!
1.0.4 / 1.0.1 New optional parameters .dumpDicts() flags: novalues, nokeys, nosum
New ways to legitimately use .dumpDicts() using above flags
Fixed bug in console section of color table (aqua/cyan was white)
.dumpDicts() to 1.0.1, see class for details
1.0.3 / 1.0.0 Added .dumpDicts() class. Lots of fun. :) Examples too. Take a look at what can be done with .d()
1.0.2 Added color synonyms to the color names supported (magenta, cyan)
Added some detail to the comments, explained how to add synonyms
1.0.1 Smarter about background colors in html, more efficient
Calling mechanism for puntReport() has changed from that in 1.0.0 -- Sorry. :(
Examples updated accordingly.
1.0.0 Initial release

dumpDicts() came about because as it turned out, I had a lot of Python dictionaries with various kinds of accumulated information. I had a lot of code to work through them, a lot of which was at least similar, if not the same -- depending on what was in the dictionary. Anyway, I got a wild hair to jam all the dictionary parsing I could think of relevant to my data reporting activities into one class. It took a few hours, but I the result is just what I wanted. If you find yourself with dictionaries full of stuff, odds are excellent this would be of direct use to you.

Here's an example using the dumpDicts() class:

Here you see some very basic setup; just two objects and a canned dictionary to generate a report from (you'll have your own dictionary, so that doesn't really count.) Then one line does all the work with d.d()

Screen shot 2015-04-25 at 6.04.40 PM

This is what you get on the console from the above. Same thing in HTML, too. :)

Screen shot 2015-04-25 at 6.04.18 PM