[Tutor] lists strings and files
Kent Johnson
kent37 at tds.net
Wed Nov 9 19:09:57 CET 2005
Michael Haft wrote:
> Hello,
> thanks for all the help with lists and strings, the list I have has
> nested sublists in it though. How do I remove these or is there a way
> to convert from lists to strings without removing them?
>
> The code looks something like:
>
> result = []
> data = [fields[1] fields[3] fields[7]]
> result.append(data)
> which gives a list containing 12 sublists
Did you miss my reply to your last thread? I said,
> 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
More information about the Tutor
mailing list