Reputation: 634
Let's say I want to take function test_function
and write it's data to a csv file that can be read by python later. How can I do that?
Just a sample function:
def test_function():
games_won = 4
games_lost = 5
average_time_sec = 6.0
some_list = [1,2,3,4]
some_tuple = (1,2,3,4)
EDIT: This is what I tried:
def test_function():
games_won = 4
games_lost = 5
average_time_sec = 6.0
some_list = [1,2,3,4]
some_tuple = (1,2,3,4)
def main():
output.write(test_function)
main()
Upvotes: 0
Views: 44
Reputation: 1785
Here is one way
import csv
import os.path
resultFile = open("path to your destination file" , 'wb')
wr = csv.writer(resultFile, dialect='excel')
some_list = [1,2,3,4]
wr.writerow(some_list)
Upvotes: 1