Python:ファイルを開く、リストするためのフィードライン、プロセスリストデータ

StackOverflow https://stackoverflow.com/questions/2773416

  •  03-10-2019
  •  | 
  •  

質問

ファイル「output.log」のデータを処理し、graphdata ['eth0]に送りたい

私はこれをしましたが、それは最初の行のみを処理します:

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)
役に立ちましたか?

解決

graphData = {}

それは辞書だと思います。それはあなたが意図したものですか?

リスト/配列を探している場合は、{}の代わりに[]を使用できます。前のポスターが言ったことは正しいように聞こえます。あなたを通して毎回GraphData = {}を設定しているため、過去から何かを上書きします。

array.append(x)

アレイに何かを追加します。

最後にすべての行をすべて幸せに表示したい場合は、ループの前にgraphData = []を設定できます。その後、ループを通してするたびに行います

graphData.append(line).  

次に、ループの後、graph_data_dict = {} graph_data_dict ['eth0'] = graph_data_arrayを設定できます

他のヒント

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つの大きなリストで食べさせてもらえますか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top