Today I got a question from a beginning python user: "How can I write an array to a file?" Initially I thought this was really trivial and something that can be done in a few lines of code. But we talked a little more and the details of what she really wanted began to emerge and things got interesting.
"Well, I really want to be able to write an HTML or LaTeX table." OK, not so hard, one just needs to make a little template and join the values appropriately. Oh, and some of the values will have error bars, and of course each column needs to be formatted in a certain way to look nice.
I realized that she had innocently stumbled onto the exact problem I've been struggling with recently: how to represent generic measurement values, i.e. values with metadata like name, classification (e.g. "powerlaw index" or "luminosity"), units and uncertainties, AND associated methods for generating formatted output in different contexts like HTML, LaTeX, plain text, etc. The latter is where I've gotten really stuck in trying to come up with a nice and generalizable system, one that will be elegant and not require too much repetition. I'd like to use the measurement classification to automatically provide defaults. For instance a powerlaw index will normally want 2 digits of precision, while a luminosity will be in a scientific notation with 2 digits of precision. So the simple question gets complicated.
QUESTION: has anyone written code or know about existing modules to address this problem?