# Exporting and importing lists of lists

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?

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

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.