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)

3 Answers 3

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

0
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)
1
  • Was there a difference there?
    – Nate
    May 5, 2010 at 13:10
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.