Message Boards Message Boards

0
|
5704 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Importing and exporting Tables with mixed dimensions

Posted 10 years ago
POSTED BY: Al Guy
4 Replies
Posted 10 years ago

Thanks!

POSTED BY: Al Guy
Posted 10 years ago

Simple text works

lm = {{{1, 2}, {4, 5}}, {5}, {1, 2, 3, 4}}
SetDirectory["H:\\"];
Put[lm, "test.txt"]
newlm = << "test.txt";
lm == newlm

Result is "True"

POSTED BY: Douglas Kubler
Posted 10 years ago
POSTED BY: Al Guy

If you want to save Mathematica symbols and variables, it might be better to save DumpSave, as in

SetDirectory[NotebookDirectory[]];
lst = {{{1, 2}, {4, 5}}, {5}, {1, 2, 3, 4}};
DumpSave["foo.mx", lst];
Clear[lst];
Get["foo.mx"];
lst
(* {{{1, 2}, {4, 5}}, {5}, {1, 2, 3, 4}} *)

You can also use "List" but you'd have to use ToExpression. So I think mx might be better

SetDirectory[NotebookDirectory[]];
lst = {{{1, 2}, {4, 5}}, {5}, {1, 2, 3, 4}};
Export["foo.txt", lst, "List"];
lst0 = ToExpression[Import["foo.txt", "List"]];
lst === lst0
(*  True  *)
POSTED BY: Nasser M. Abbasi
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