Mike Haft wrote:
> All the ways of writing data to a file I know keep telling me that lists
> can't be written to the file. I'm trying to convert data from one set of
> files into files of a different format. But the easiest way to get the
> data from the first set of files is in a list(s).
> 
> So, is there any way to convert lists to strings? Or a way to write lists
> to a file?

What do you want the data to look like in the file? You can create a string 
from your list and write the string to the file. For example if the list 
contains strings and you just want to separate the values with spaces use 
join():

 >>> data = ['22.5', '0.3', '11.9']
 >>> ' '.join(data)
'22.5 0.3 11.9'

Or you could separate the values with comma and space:
 >>> ', '.join(data)
'22.5, 0.3, 11.9'

I think from your previous post that your actual data is a list of lists, so 
you have to iterate the outside list, formatting each line and writing it to 
the file, something like this (borrowing from your previous unanswered post):

out_file = open("test.txt","w")
data = readSOMNETM(filename)
for line in data:
  line = ' '.join(line)
  out_file.write(line)
  out_file.write('\n')  # need a newline after each line
out_file.close()

Kent



-- 
http://www.kentsjohnson.com

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to