I have been writing a script that fetches data from 3 external sources.
def fetch1():
return array
def fetch2():
return array2
def fetch3():
return array3
All the elements of list are associated with each other. i.e. array[0],array2[0],array3[0] should be put together in a csv.
Some of the elements of array2 might be blank.
Now I want to write all of them in a csv file. Example of arrays :
array = ["dog", "cat", "horse", "lion"]
array2 = ["500USD", "300USD", "900USD", ""]
array3 = ["Buy", "Sell", "Buy", "Buy"]
And how to write them in a way that every time I start this script, data should be entered after the data that was previously entered, instead of making a new file.
What I have tried so far:
I have created a dictionary of array and array2 because of the fact that array2 elements can be null. Then I have written the following function.
def write():
writer = csv.writer(open('dict.csv', 'wb'))
for key, value in arrayNarray2.items():
writer.writerow([key.encode("UTF-8"), value.encode("UTF-8")])