0
$\begingroup$

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>

enter image description here

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

enter image description here

$\endgroup$
  • $\begingroup$ Drop Grid and Export to the "Table" format. $\endgroup$ – Szabolcs Mar 17 '15 at 13:58
  • $\begingroup$ I'm not sure what you mean here. I toyed around with Table, but don't get it to work. $\endgroup$ – Mockup Dungeon Mar 17 '15 at 17:12
  • $\begingroup$ 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). $\endgroup$ – Szabolcs Mar 17 '15 at 17:42
  • $\begingroup$ I meant this, but maybe I misunderstood what you were trying to do. $\endgroup$ – Szabolcs Mar 17 '15 at 21:51
  • $\begingroup$ 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. $\endgroup$ – Mockup Dungeon Mar 18 '15 at 9:32
1
$\begingroup$

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.

Mathematica graphics

Instead you can do this

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

Mathematica graphics

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

And this is the text file

Mathematica graphics

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Mockup Dungeon Mar 17 '15 at 11:45
  • $\begingroup$ @MockupDungeon Try Export["foo.txt", data, "Table"]. $\endgroup$ – Karsten 7. Mar 17 '15 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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