Message Boards Message Boards

0
|
3375 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

import and export list: input and output do not match

Posted 11 years ago
Hi All

I am trying to export and then import a list; I woud like to obtain exactly the same list that I exported. I do this:

initial = {{{2013, 1, 2}, 41}, {{2013, 1, 3}, 42}};
initial // TableForm
Export["out.txt", initial, "List"];
final = Import["out.txt", "List"]
final // TableForm
and I get that "final" is different from "initial", see the attached pdf. I tried all possible combinations of "List" and "Table" and nothing works.
I use Mathematica 9 on Mac OSX 10.9

Thanks for any help

Luca
Attachments:
POSTED BY: luca bardill
3 Replies
Posted 11 years ago
In[1]:= initial = {{{2013, 1, 2}, 41}, {{2013, 1, 3}, 42}};
initial >> "out.txt";
final = << "out.txt";
initial == final

Out[4]= True
POSTED BY: Bill Simpson
Note that for your example the Import is returning a list of Strings rather than the actual list elements that you are desiring. (The explicit String characters are suppressed in Mathematica output by default.) Thus using the following will give you your original  
final = ToExpression /@ Import["out.txt", "List"]
POSTED BY: David Reiss
Posted 11 years ago
Thanks a lot to both!

I actually had tried before the solution suggested by Bill Simpson but forgot the equal sign in the
=<<
expression, so it didn't work. Now is all fine.
POSTED BY: luca bardill
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract