MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Printing Lists to file without {}

  • To: mathgroup at
  • Subject: [mg66083] Re: Printing Lists to file without {}
  • From: albert <awnl at>
  • Date: Sat, 29 Apr 2006 03:40:15 -0400 (EDT)
  • References: <e2srqd$3o2$>
  • Sender: owner-wri-mathgroup at


just generate the string you want to see in the file in mathematica and
write that string, something like:

In[1]:= lst = {1,2,3,4,5}

Out[1]= {1, 2, 3, 4, 5}

In[2]:= line = StringJoin[StringTake[StringJoin[
     ({ToString[#1], ","} & ) /@ lst], {1, -2}], "\n"]

Out[2]= 1,2,3,4.,0.00005

In[3]:= WriteString["file.csv",line]

It should be fairly easy to adopt this to your needs with the use of the
String*-functions and probably something like NumberForm for finetuning the
formatting of the numbers. Just look that stuff up in the help browser...

If speed matters, this is probably not optimal. For one it might be more
efficient to collect some lines and write them with one call to
WriteString. Using regular expressions to convert a whole bunch of lines to
what you want them to look like could also be more efficient than
complicated combinations of StringJoin/StringTake and the like, but that I
don't know.



  • Prev by Date: Re: A Conditional File Import
  • Next by Date: Re: How Functions are Applied to Matrices
  • Previous by thread: Re: Printing Lists to file without {}
  • Next by thread: Setting up equations