1

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)
unwind
  • 391,730
  • 64
  • 469
  • 606
krisdigitx
  • 7,068
  • 20
  • 61
  • 97

3 Answers3

0
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
  • 7,068
  • 20
  • 61
  • 97
0

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

Nate
  • 484
  • 3
  • 6
0
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
  • 1,931
  • 1
  • 24
  • 38