1
$\begingroup$

I observed that when exporting a List, no matter if I put "List" or "cvs" the result is always the same: after importing, the data appears with quotations:

   cont1 = {{2, 3}, {3, 4}, {5, 6}};
   cont2 = {{7, 8}, {9, 10}, {11, 12}};
   tosave = {cont1, cont2};

   Export["ContTest.lst", tosave, "List"];
   Export["ContTest.csv", tosave, "csv"];
   asDat = Import["ContTest.lst", "List"]
   asCsv = Import["ContTest.csv", "csv"]

Out[540]= {"{{2, 3}, {3, 4}, {5, 6}}", "{{7, 8}, {9, 10}, {11, 12}}"}

Out[541]= {{"{2, 3}", "{3, 4}", "{5, 6}"}, {"{7, 8}", "{9, 10}", "{11, 12}"}}

The solution I found is to export in ".cvs" format and transform with ToExpression:

     merd = ToExpression@Import["ContTest.csv", "csv"]

Out[520]= {{{2, 3}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}, {11, 12}}}

How to avoid the quotations when using "List"? Or better, why the list is imported with quotations?

$\endgroup$
  • $\begingroup$ It is not clear to my what the question is. Please rephrase it and illustrate it with an example. If something doesn't show, show what you did. $\endgroup$ – Szabolcs May 11 '18 at 14:49
  • $\begingroup$ For example, one can only guess at what you might mean by no matter if I put "List","Data" or whatever. $\endgroup$ – Szabolcs May 11 '18 at 14:49
  • $\begingroup$ I do not see why you need ToExpression here. Even without that, things are okay. To keep things simple, you might want to export in `.m' format. $\endgroup$ – Himalaya Senapati May 11 '18 at 14:56
  • $\begingroup$ I already have a large amount of data exported in "List" format... that´s why I would like to import and recover it in the original format ("List") $\endgroup$ – Juan Manuel Gomba May 11 '18 at 14:59
  • $\begingroup$ @JuanManuelGomba If the format is indeed "List" as you claim, why do you import as "CSV"? Also, it would help to see the problematic data, since, as @HimalaySenapati already pointed out, the example provided works as expected $\endgroup$ – Lukas Lang May 11 '18 at 15:05
1
$\begingroup$
cont = {{2, 3}, {3, 4}, {5, 6}};

Put[cont, cont, "data"]

merd = ReadList["data"]

{{{2, 3}, {3, 4}, {5, 6}}, {{2, 3}, {3, 4}, {5, 6}}}

or if the brackets are included

Put[{cont, cont}, "data"]

merd = Last@ReadList["data"]

{{{2, 3}, {3, 4}, {5, 6}}, {{2, 3}, {3, 4}, {5, 6}}}

merd == {cont, cont}

True

$\endgroup$
  • $\begingroup$ Thanks Chris, but it does not have the same format as {cont,cont} $\endgroup$ – Juan Manuel Gomba May 11 '18 at 15:26
  • $\begingroup$ @JuanManuelGomba You mean you need the brackets included? Added edit. $\endgroup$ – Chris Degnen May 11 '18 at 15:30
  • $\begingroup$ Great, thanks. Now I see that if I directly write ReadList["ContTest.lst] the list is correctly read. $\endgroup$ – Juan Manuel Gomba May 11 '18 at 16:39
1
$\begingroup$

From Chris Degnen post I find that just doing

  ReadList["ContTest.lst"]

the data is obtained without quotations.

$\endgroup$

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.