Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

Export["listname",list,"RawData"] 

and also

Export["listname",list,"Data"]

but getting the following error:

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

This works for other formats such as CSV or TXT.

share|improve this question
    
Have you seen DumpSave[]? –  belisarius Mar 11 at 11:12
    
@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! –  someuser_ Mar 11 at 11:30
    
@Ö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. –  someuser_ Mar 11 at 11:36
    
"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 –  george2079 Mar 11 at 12:22
    
@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"] –  someuser_ Mar 11 at 12:32

1 Answer 1

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

list = {1, a, π};

Put[list, "test.anything"];    
Get["test.anything"]

(* {1, a, π} *)

Export["test.wdx", list];   
Import["test.wdx"]

(* {1, a, π} *)
share|improve this answer
    
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 –  Daniel Mar 11 at 15:26
    
Thanks!! It also works with Save["test",list] and Get["test"] –  someuser_ Mar 13 at 16:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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