我有一個腳本,基本上讀取文本文件並創建8個列表。如果它從第1行讀取文件,它會很好地工作。我需要它從177行開始讀取文本文件到352行(這是最後一行)。如何在Python 2.6中的特定行之後處理數據?
這是我的腳本和變化。我沒有收到任何錯誤,但沒有任何結果。程序掛起有無反應:
f = open("Output1.txt", "r")
lines = [line.rstrip() for line in f if line != "\n"] #Get all lines, strip
newline chars, and remove lines that are just newlines.
NUM_LISTS = 8
groups = [[] for i in range(NUM_LISTS)]
listIndex = 0
for line in lines:
while line > 177: #here is the problem
if "Transactions/Sec for Group" not in line:
groups[listIndex].append(float(line))
listIndex += 1
if listIndex == NUM_LISTS:
listIndex = 0
value0 = groups[0]
value1 = groups[1]
value2 = groups[2]
value3 = groups[3]
value4 = groups[4]
value5 = groups[5]
value6 = groups[6]
value7 = groups[7]
json_file = 'json_global.json'
json_data = open(json_file)
data = json.load(json_data)
for var1 in range(0, 11):
a = value0[var1]
b = value1[var1]
c = value2[var1]
d = value3[var1]
e = value4[var1]
f = value5[var1]
g = value6[var1]
h = value7[var1]
var2 = var1 + 57
item = data[var2]['item']
cmd = data[var2]['command']
var1+= 1
print item, cmd, a, b, c, d, e, f, g, h)
謝謝@kittykittybangbang – Gusbok
sed -n'177,352p'| python scriptname – Marichyasana
不客氣,@Gusbok。 :) – kittykittybangbang