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$
7
  • $\begingroup$ Drop Grid and Export to the "Table" format. $\endgroup$
    – Szabolcs
    Commented Mar 17, 2015 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$ Commented Mar 17, 2015 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
    Commented Mar 17, 2015 at 17:42
  • $\begingroup$ I meant this, but maybe I misunderstood what you were trying to do. $\endgroup$
    – Szabolcs
    Commented Mar 17, 2015 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$ Commented Mar 18, 2015 at 9:32

1 Answer 1

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$
2
  • $\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$ Commented Mar 17, 2015 at 11:45
  • 1
    $\begingroup$ @MockupDungeon Try Export["foo.txt", data, "Table"]. $\endgroup$
    – Karsten7
    Commented Mar 17, 2015 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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