I've been using the weather site Open Weather Map (https://openweathermap.org/) to get details for a project in Python.
rain = w.get_rain() # Get rain volume {'3h': 0}
wind = w.get_wind() # Get wind degree and speed {'deg': 59, 'speed': 2.660}
humidity = w.get_humidity() # Get humidity percentage 67
And then insert them the variables into a database, which doesn't like '{' '}'.
I've tried removing the '{' '}' from the outputs, looking at replies from this site. Strip:
rain = rain.strip(['{','}'])
and Replace:
rain = rain.replace('{', ' ')
But all I'm getting are "AttributeError: 'dict' object has no attribute". Is there another escape clause I could use for the variable to remove the unwanted characters?
jsonmodule to work with the responses. Further, you should be using your database API to deal with special characters if you really want to store the entire JSON result, not just an extracted value, rather than trying to manually escape things.AttributeErrorcomes from the fact that you do have adict, not a JSON object, which raises the question of what you mean by the database not liking the braces.)