My problem is quite simple yet I do not seem to figure out the solution to it. I am simply trying to export a list in Mathematica, actually a list of lists of lists etc, something like {{...,{...}},{...}}, but the Head is a list. I want to export this as raw Mathematica symbols so that I can access it later.

Lets take a simple list, say

list = {1,a,Pi};

I am trying:


and also


but getting the following error:

Export::infer: Cannot infer format of file listname. >>

This works for other formats such as CSV or TXT.

  • $\begingroup$ Have you seen DumpSave[]? $\endgroup$ – Dr. belisarius Mar 11 '14 at 11:12
  • $\begingroup$ @belisarius was not aware of DumpSave[] and Save[] which seem to work for my purpose. Still don't understand why Export[] does not work but thanks for the tip! $\endgroup$ – someuser_ Mar 11 '14 at 11:30
  • $\begingroup$ @Öskå saving as "Text" does not work well in my case because I am actually trying to save lists with many different levels. It would be ideal to just save in Mathematica format. $\endgroup$ – someuser_ Mar 11 '14 at 11:36
  • $\begingroup$ "data" is an element not a format. The error is because you havent specified a format and none can be inferred from the file name $\endgroup$ – george2079 Mar 11 '14 at 12:22
  • $\begingroup$ @george2079 Thanks for clearing that but could you be more explicit? How could I save my list without converting it to another data format? I guess the command would be Export["Listname.(some extension)", list, "Data"] $\endgroup$ – someuser_ Mar 11 '14 at 12:32

Two options for exporting arbitrary Mathematica expressions are to use Put or to Export to WDX format.

list = {1, a, π};

Put[list, "test.anything"];    

(* {1, a, π} *)

Export["test.wdx", list];   

(* {1, a, π} *)
  • $\begingroup$ I've seen people suggest exporting using Compress as well - I don't have the experience to say if this is worth mentioning or not $\endgroup$ – Daniel Mar 11 '14 at 15:26
  • $\begingroup$ Thanks!! It also works with Save["test",list] and Get["test"] $\endgroup$ – someuser_ Mar 13 '14 at 16:20

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.