how to fix TypeError: format requires a mapping

Hina Imran hinaimran.mehr at gmail.com
Thu Jul 2 03:44:03 EDT 2015


you are right the data is a list of dictionaries. When I try your solution I get an error 

Traceback (most recent call last):
  File "data.py", line 45, in <module>
    col['x'] = row['timestamp']
TypeError: 'OldSample' object has no attribute '__getitem__'






On Wednesday, July 1, 2015 at 11:57:39 PM UTC+2, Hina Imran wrote:
> I am pulling my hair with this problem right now,
> 
> I have the following Data structure 
> 
>     [<OldSample {u'counter_name': u'cpu_util', u'user_id': u'id', u'resource_id': u'id', u'timestamp': u'2015-06-30T15:53:55', u'counter_volume': 0.043}]
> 
> I need to make it something like this to put in EON pubnub charting libaray (see link: http://www.pubnub.com/developers/eon/chart/spline/)
> 
>     message: {
>           columns: [
>             ["y": 0.043, "x": "2015-06-30T15:53:55"],
>             ["y": 0.045, "x": "2015-06-30T15:53:55"]
>           ]
> 
> Now I have the following code 
> 
>     data = cclient.samples.list(meter_name ='cpu_util', limit=2)
> 
> result_rows = []
> for row in data:
>      formatted = """["y": %(counter_volume)0.3f, "x": "%(timestamp)s"]""" % (row)
>      result_rows.append(formatted)
>      
>      print(',\n'.join(result_rows))
> 
> 
> clean_json(data)




More information about the Python-list mailing list