twitter - Saving tweets in a file, but they are overwritten by Python -


i kind of new in programming. have created script loops through list of twitter ids, retrieves timelines , saves them in json archive. however, think each time takes last timeline , overwrites file , keeps last one.

this code in loop:

idfile = open('ids_part1.txt', 'r+') id in idfile:     if id:         id = id.strip()         try:             result = ret_timeline(user_id=id)             if result:                 result_file = open('result1.json', 'w+')                 st in result:                     result_file.write(json.dumps(st._json, indent=4, sort_keys=true))                 result_file.close() 

can please me that? thank much!

you need open file in append mode, , should fine

result_file = open('result1.json', 'a') 

Comments