# Making a simple text log file

I have a model and want to export the run parameters to a log file. The idea is to get the following example into a decent text export:

a = 1;
b = 2;
c = 3;

p = Style[Grid[{
{"Parameter a ", a},
{"Parameter b ", b},
{"Parameter c ", c}
}]
, Bold, Blue]

Export["_log.txt", p];


The problem here is, that the output includes all the Grid commands, which I obviously don't want. Just a somewhat neatly arranged text file.

More precisely: the above code gives the following log file>

The log file I'd like to have should look like>

• Drop Grid and Export to the "Table" format. Mar 17 '15 at 13:58
• I'm not sure what you mean here. I toyed around with Table, but don't get it to work. Mar 17 '15 at 17:12
• Please make it clear what you are trying to achieve. Give both a sample input (you have this) and a sample output (you didn't show this). Mar 17 '15 at 17:42
• I meant this, but maybe I misunderstood what you were trying to do. Mar 17 '15 at 21:51
• OK, great: Export["Desktop/_log.txt", ExportString[p, "Table"]] at least produces a simple log file I can use. Thanks! However, I am wondering how it is possible to export a more complex info file. But for now, that is sufficient. Mar 18 '15 at 9:32

You have wrapped your data with UI specific calls that makes sense only the UI. And then wanted to export it to a text file, which is not a good way to go about things.

You should have your data separate from the UI specific wrappers, then you can export your data on its own, or use the wrappers on it for UI display. Look at InputForm[p] and you can see what you have now.

a = 1;
b = 2;
c = 3;
data = {{"Parameter a ", a}, {"Parameter b ", b}, {"Parameter c ", c}};
p = Style[Grid[data], Bold, Blue]


SetDirectory[NotebookDirectory[]]
Export["foo.txt", data]


And this is the text file

• Right, I tried this, but I don't want the brackets or quotations marks, just some neat, simple text, maybe comma separated, but just text. Mar 17 '15 at 11:45
• @MockupDungeon Try Export["foo.txt", data, "Table"]. Mar 17 '15 at 19:06