Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pass an arbitrary number of arguments to a function in Python (Facepy library)?
    primarykey
    data
    text
    <p>I'm trying to pass an arbitrary number of arguments to a function, and I keep getting errors, and not quite sure where I'm going wrong. This is the first time I've attempted to use **kwargs.</p> <p>More specifically, I'm trying to use the Facepy library to get data from Facebook's Graph API. According to the documentation (<a href="https://facepy.readthedocs.org/en/latest/usage/graph-api.html" rel="nofollow">https://facepy.readthedocs.org/en/latest/usage/graph-api.html</a>), the <code>get</code> method should accept optional parameters like "since", "until", etc. Since I only want to pass some of these parameters on any given query, this seems like an ideal time to use **kwargs.</p> <p>First I create a function that wraps the Facepy library:</p> <pre><code>def graph_retriever(object_id, metric_url, **kwargs): #optional args that I want to pass include since, until, and summary graph = facepy.GraphAPI(access_token) retries = 3 # An integer describing how many times the request may be retried. object_data = graph.get('%s/%s' % (object_id, metric_url), False, retries, **kwargs) return object_data </code></pre> <p>Here's two examples where I call the function with different arguments:</p> <pre><code>for since, until in day_segmenter(start, end): # loop through the date range raw_post_data = graph_retriever(str(page), 'posts', {'since': since, 'until': until}) </code></pre> <p><code>post_dict['comment_count'] = graph_retriever(post_id, 'comments', {'summary':1})['summary']['total_count']</code></p> <p>However, when I try to run this, I get the following error:</p> <p><code>Traceback (most recent call last): raw_post_data = graph_retriever(str(page), 'posts', {'since': since, 'until': until}) TypeError: graph_retriever() takes exactly 2 arguments (3 given)</code></p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload