0

Hi,

i have a list that contains 5 columns that contains strings and float values(3 strings columns and 2 float columns) ..

i want to export this list to a space separated text file (each column in the list is a column in the text file)

i tried to do this:

text_file = open("output/resfile.txt", "w")
for fw in len(range(list)):
    text_file.write(list[fw][0] + " " + list[fw][1] + "\n")

but it's not working,

how can i do the export easily in python??

thank you ..

2
Contributors
7
Replies
9
Views
5 Years
Discussion Span
Last Post by Sky Diploma
0

Convert your float values into a String using the str() function and then try to write it. This is because the write() only takes string arguments.

0

This is the easiest way I can think of. I mean its just surrounding str( ) around the 2 float elements while in the write().

0

ok, and how to separate columns by spaces??

Edited by weblover

0

This is just a small example.

my_list=[13.34,12.25,11.23]
file=open("myfile",'w');
for li in my_list:
    file.write(str(li)+" "+"my other values" )

Is it unclear?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.