arze ramade
arze ramade

Reputation: 317

write into a text file issue

I have this simple python code:

import facebook # pip install facebook-sdk
import json
import codecs
    ACCESS_TOKEN = ''
g = facebook.GraphAPI(ACCESS_TOKEN)

for i in range (0,2):

    f = open("samples"+str(i)+".txt", 'w')

    my_likes = [ like['id'] 
             for like in g.request('search', { 'q' : '&','type' : 'page', 'limit' : 5000 ,'offset' :i , 'locale' : 'ar_AR' })['data'] ]

    f.write( my_likes )
    f.close()

what I want to do is to store data exists on my_likes list into a text file. but a write() takes "no keyword arguments" error message appear to me. what am I doing wrong here?

edit: if I remove indent=1 an error message appears: "expected a character buffer object"

Upvotes: 0

Views: 1643

Answers (1)

jonrsharpe
jonrsharpe

Reputation: 122026

what I am doing wrong here?

The error message tells you what you are doing wrong; you are passing a keyword argument (indent=1) to write(), which shouldn't have any. As per the documentation, write only has one argument, the string to write. If you want to indent it in the file, add a tab ('\t') to the start of each line in the string.

Upvotes: 1

Related Questions