3
$\begingroup$

I have a list of lists of data on the following form (one element):

{"NYSE:AEM", 7.13*10^9, "Gold", {{2014, 4, 16}, {2014, 5, 2}, {2014, 7, 31}}}

And all I want to do is export it, and then import it again. But in what format am I supposed to do that? Using .dat will corrupt the data:

{"NYSE:AEM", 7.13*10^9, "Gold", "{{2014,", "4,", "16},", "{2014,", "5,", "2},",\"{2014,", "7,", "31}""}"}

And I am interested in saving other sorts of lists of lists as well, with different formats mixed (text, integers, dates, ...).

Is there a way to safely save any mathematica list so that it can be retrieved again?

$\endgroup$
5
  • $\begingroup$ Have you given them variable names? Or tried using export or import? $\endgroup$
    – wgwz
    Feb 12, 2015 at 14:07
  • $\begingroup$ @skywalker Yes, what I have done is: Export["allCompanyData.dat", myCompanyData]. Which then, when imported: Import["allCompanyData.dat"] creates the above corruption. $\endgroup$
    – V.E.
    Feb 12, 2015 at 14:10
  • 1
    $\begingroup$ A good question! $\endgroup$ Feb 12, 2015 at 14:19
  • 2
    $\begingroup$ If it is only for you, maybe .mx? :) $\endgroup$
    – Kuba
    Feb 12, 2015 at 14:29
  • $\begingroup$ @Kuba Perfect, that's what I was looking for. $\endgroup$
    – V.E.
    Feb 12, 2015 at 14:32

1 Answer 1

3
$\begingroup$

Export has an optional third argument which allows to specify the export format independent of the file extension. In your case, calling

Export["file.dat", data, "Package"];

should work fine.

Analogously, Import has an optional second argument for the same purpose. Load your file with

data2 = Import["file.dat", "Package"];

Alternatives to "Package" are, e.g., "MX" or "WDX", but I find them less performant.

$\endgroup$

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.