I'm fairly new to oop and had a quick question about constructors. From an API call i get a large response of which I only want to preserve a subset in a class based data structure. This is the approach i was thinking about, but I think i would be calling the api twice, whereas, I just want to call it once , preserve the data and then extract pieces into the constructors.
I could call the api, outside of the function, just passing in the appropriate values into the constructors, but thought it might be cleaner to keep all the logic in the folder class.
Example code
class folder():
def __init__(self, id):
self.id = id
self.name = get_folder_metadata(id).name
self.region = get_folder_metadata(id).region
def get_folder_metadata(id):
f_metadata = '''api call''' getfolder(id) ''' done '''
return f_metadata
Curious if either is best practice or there are other ways i'm not thinking about. Thanks for any help.