In this case I'd suggest writing to CSV (comma separated values) files, as they can easily be read both as text files and in Excel (and other spreadsheet packages). As for how to write them in Python, there are a number of options:You could simply write the data using the standard text file writing python commands (see http://snipplr.com/view/6630/reading-and-writing-text-files-in-python/ for a simple tutorial) and put comma's between them. For example, I used the following code in one of my projects:# Open the file
FILE = open(output_file, "a")
# Write the header (so I can remember what each column is!)
FILE.write("name,n,mean_len,total_len,max_len,min_len,stdev_len,mean_closeness,std_closeness,defect_dens,r_score,z_score,p_value\n")
# Get the line that I need to write to the CSV file (it is returned from a function I wrote to do my processing)
csv_line = process_file(full_path)
# Print it to the screen (just for testing really)
print csv_line
# Write it to the file
FILE.write(csv_line + "\n")
# Close the file
FILE.close()
Of course, I also had some code within the process_file() function which created the line of CSV to write:# Put all of the statistics into a list - in this case all of the items in the list are variables that I have calculated
output_stats = [tidied_file_name, n_dunes, mean_len, total_len, max_len, min_len, stdev_len, mean_closeness, std_closeness, defect_dens, r_score, z_score, p_value]
# For each of the items in this list, convert it to a string and append to an array
for item in output_stats:
csv_array.append(str(item))
# Join this array, adding commas between all the items
csv_string = ",".join(csv_array)
# Return this comma joined array ready to write to the file
return csv_string
The alternative is to use a Python library like the CSV library (http://docs.python.org/library/csv.html) which comes with functions to read and write CSV files.Hope that helps,Robin