Reputation: 11
I have write this code to save the id
and tweet
I extract from specific user but the problem is it save only the first tweet with index 50 I try the counter but nothing happens.
a=50
for info in tweets[:a]:
with open(userID+'.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["id", "tweet"])
writer.writerow([info.id,info.full_text+ "\n"])
a-=1
Upvotes: 0
Views: 83
Reputation: 455
Use append mode instead of write.
with open(userID+'.csv', 'a', newline='') as file:
'w' : write mode actually replaces the existing content. 'a' : append mode adds data to the existing file. Read here : https://www.guru99.com/reading-and-writing-files-in-python.html
Upvotes: 1