简体   繁体   中英

What does “TypeError: [foo] object is not callable” mean?

I am trying to iterate through a list of Facebook postIDs, and I am getting the following error:

TypeError: 'list' object is not callable

Here is my code:

MCTOT_postIDs = [["126693553344_10155053097028345"],
["126693553344_10155050947628345"],
["126693553344_10155048566893345"],
["126693553344_10155044677673345"],
["126693553344_10155042089618345"],
["126693553344_10155035937853345"],
["126693553344_10155023046098345"]]

g = facebook.GraphAPI()
g.access_token = g.get_app_access_token(APP_ID, APP_SECRET)

for x in MCTOT_postIDs():
g.get_object('fields="message, likes, shares')

I know I am making a basic error somewhere, but I can't seem to figure it out. Thanks!

EDIT: For the other error, the function g.get_object(...) requires one more argument, that you are not passing. You're passing the fields, but you're must pass an ID as an argument too, you must pass the x of your loop, that contains the id.

Probably should go like:

g.get_object('fields="message, likes, shares', x)

or maybe

g.get_object('fields="message, likes, shares', x[0]) 

if you need to pass it as a string, not an array (your list is a list of arrays) but this should be a topic for a new question...


The error message says:

TypeError: 'list' object is not callable

So look again at your code: when you try to do the for ... in loop, you're trying to call your list, as if it was a function.

You're doing

for x in MCTOT_postIDs():

When you should be doing

for x in MCTOT_postIDs:

The list is not callable, and the () is used for calling a function (meaning: execute the function). Remove it and it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM