新着アラート!テキストファイルを順番に読み込んで、特定の行に戻ってそこからやり直す方法
Path = "C:/Users/Kailash/Downloads/Results_For_Stride-Table.csv"
counter_start = 0
counter_end = 0
num_lines = len(open(Path).read().splitlines())
print("num_lines = ", num_lines)
with open(Path, "r") as f:
for lines in f:
print("lines = ", lines)
counter_end += 1
Stride_Length = lines.split(", ")
Previous_Sum = distances
Previous_Sum_GCT = Total_GCT
Previous_Heading = Sum_Heading
GCT = float(Stride_Length[2])
Total_GCT += GCT
print("Total_GCT = ", Total_GCT)
distances += float(Stride_Length[3])
print("distances = ", distances)
Sum_Heading += float(Stride_Length[7])
print("Sum_Heading = ", Sum_Heading)
print("counter_end = ", counter_end)
if(GCT == 0.00):
distances = 0
counter_end = 0
if distances > 762:
print("counter_end = ", counter_end)
counter_start = counter_end
lines_test = f.readlines()
print("counter start = ", counter_start)
print("move = ", lines_test[counter_start-counter_end-1])
print("Distance is above 762")
distances = 0
ファイルの特定の行に戻って、そこから再びPythonで読む方法を知りたいと思います。コードの最後の5行目にf.readlines()を使用しようとすると、処理がすぐに停止します。