python - Append to list error: 'str' object has no attribute 'append' -


graph = [] double in change:     year = str(double[1].year)     month = str(double[1].month)     day = str(double[1].day)     hour = str(double[1].hour)     string = '{ x: new date('+year+','+month+','+day+','+hour+'), '+'y:'+str(double[0])+'}, '     graph.append(string)         graph = ''.join(graph)     print "graph is:"+graph   

i not understand why not work , gives error 'str' object has no attribute 'append'

note change list of lists. in specific case, looks this:

[[1.0, datetime.datetime(2015, 7, 3, 1, 0)], [2.0, datetime.datetime(2015, 7, 3, 2, 0)]] 

the goal get:

'{ x: new date(2015,7,3,1), y:1.0}, ', '{ x: new date(2015,7,3,2), y:2.0}, '

you trying concatenate string , list, why getting error.

import datetime change = [[1.0, datetime.datetime(2015, 7, 3, 1, 0)], [2.0, datetime.datetime(2015, 7, 3, 2, 0)]] graph = [] double in change:     year = str(double[1].year)     month = str(double[1].month)     day = str(double[1].day)     hour = str(double[1].hour)     string = '{ x: new date('+year+','+month+','+day+','+hour+'), '+'y:'+str(double[0])+'}'     graph.append(string)  print ', '.join(graph) 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -