How do I best store API data into a Python class instance variable?
<p>I would like some advice on how to best design a class and it's instance variables. I initialize the class with self.name. However, the main purpose of this class it to retrieve data from an API passing self.name as a parameter, and then parsing the data accordingly. I have a class method called <code>fetch_data(self.name)</code> that makes the API request and returns ALL data. I want to store this data into a class instance variable, and then call other methods on that variable. For example, <code>get_emotions(json), get_personality_traits(json), and get_handle(json)</code>, all take the same dictionary as a parameter, assign it to their own local variables, and then manipulate it accordingly. </p>

<p>I know I can make fetch_data(self.name) return data, and then call fetch_data(self.name) within the other methods, assign the return value to a local variable, and manipulate that. The problem is then I will need to call the API 5 times rather than 1, which I can't do for time and money reasons. </p>

<p>So, how do I make the result of <code>fetch_data(self.name)</code> global so that all methods within the class have access to the main data object? I know this is traditionally done in an instance variable, but in this scenario I can't initiliaze the data since I don't have it until after I call <code>fetch_data()</code>. </p>

<p>Thank you in advance!</p>