I would like my class to have a set of default settings, here is my attempt:
import requests
defaultConfig = {
'endpoint': 'http://localhost:4333/api/data'
}
class DataRenderer:
def __init__(self, config = defaultConfig):
self.config = config
def drawGraph(self, options):
retu requests.post(self.config.endpoint, json = {
data: {
'action': 'drawGraph',
'graph': options
}
})
I get a AttributeError: 'dict' object has no attribute 'endpoint' error. It picks up that it's a dictionary object, but oddly the attributes don't seem to be initialized yet? Is there a better way to achieve the same thing (without inlining the whole dictionary in the args)
