views:

66

answers:

4

I want to process the data in the file "output.log" and feed it to graphdata['eth0]

I have done this but it process only the first line:

logread = open("output.log", "r").readlines()
for line in logread:
        print "line", line
        i = line.rstrip("\n")
        b = float(i)
        colors = [ (0.2, 03, .65), (0.5, 0.7, .1), (.35, .2, .45), ]
        graphData = {}
        graphData['eth0'] = [b]
        cairoplot.dot_line_plot("./blog", graphData, 500, 500, axis=True, grid=True, dots=True, series_colors=colors)
A: 
logread = open("output.log", "r").readlines()
for line in logread:
        print "line", line
        i = line.rstrip("\n")
        b = float(i)
        colors = [ (0.2, 03, .65), (0.5, 0.7, .1), (.35, .2, .45), ]
        graphData = {}
        graphData['eth0'] = [b]
        cairoplot.dot_line_plot("./blog", graphData, 500, 500, axis=True, grid=True, dots=True, series_colors=colors)
krisdigitx
Was there a difference there?
Nate
A: 

Not entirely sure, bit it looks like you're re-initing the array each time. Can you feed it in one big list?

Nate
A: 
graphData = {}

I believe that is a dictionary. Is that what you intended?

If you're looking for a list/array you can use [] instead of {}. What a previous poster said sounds correct. Every time through you are setting graphData = {} and therefore overwriting anything from the past.

array.append(x)

will append something to an array.

If you want all lines displayed all happily at the end you could set graphData = [] before the loop. Then each time through the loop do the

graphData.append(line).  

Then after the loop you can set graph_data_dict = {} graph_data_dict['eth0'] = graph_data_array

wilbbe01
that worked...thanks..
krisdigitx
A: 

cool..it worked like charm..

    graphData = []
logread = open("output.log", "r").readlines()
for line in logread:
    print "line", line
    i = line.rstrip("\n")
    b = float(i)
    colors = [ (0.2, 03, .65), (0.5, 0.7, .1), (.35, .2, .45), ]
    graphData.append(b)
    #graphData['eth0'] = [50,70,90,40]
    cairoplot.dot_line_plot("./blog", graphData, 500, 500, axis=True, grid=True, dots=True, series_colors=colors)
    print "1st data", b
krisdigitx