是否可以向此代碼添加while循環?所以它可以連續獲得線條塊,直到它仍然可以看到開始和結束字。如何連續讀取文本的細節和行數的塊
with open('test.txt') as input_data:
for line in input_data:
if line.strip() == 'Start':
break
for line in input_data:
if line.strip() == 'End':
break
print line
如果您要從我的文本文件中獲取數據,我需要從VIDEO字符串開始直到AUDIO字符串。然後從AUDIO到MKV。它應該一直持續到文件結束。這是我的文件的示例。
*****START OF YOUTUBE*****
VIDEO
[download] 0.0% of 5.30MiB at 188.75KiB/s ETA 00:29
[download] 0.1% of 5.30MiB at 474.99KiB/s ETA 00:11
[download] 0.1% of 5.30MiB at 984.97KiB/s ETA 00:05
[download] 0.3% of 5.30MiB at 1.85MiB/s ETA 00:02
[download] 0.6% of 5.30MiB at 896.97KiB/s ETA 00:06
[download] 1.2% of 5.30MiB at 888.54KiB/s ETA 00:06
[download] 2.3% of 5.30MiB at 1006.45KiB/s ETA 00:05
[download] 4.7% of 5.30MiB at 916.41KiB/s ETA 00:05
[download] 9.4% of 5.30MiB at 863.70KiB/s ETA 00:05
[download] 18.9% of 5.30MiB at 847.73KiB/s ETA 00:05
[download] 34.2% of 5.30MiB at 843.72KiB/s ETA 00:04
[download] 49.7% of 5.30MiB at 840.54KiB/s ETA 00:03
[download] 65.0% of 5.30MiB at 839.77KiB/s ETA 00:02
[download] 80.5% of 5.30MiB at 839.71KiB/s ETA 00:01
[download] 95.9% of 5.30MiB at 839.39KiB/s ETA 00:00
[download] 100.0% of 5.30MiB at 842.74KiB/s ETA 00:00
[download] 100% of 5.30MiB in 00:06
AUDIO
[download] 0.0% of 2.99MiB at 112.61KiB/s ETA 00:27
[download] 0.1% of 2.99MiB at 311.43KiB/s ETA 00:09
[download] 0.2% of 2.99MiB at 682.19KiB/s ETA 00:04
[download] 0.5% of 2.99MiB at 1.32MiB/s ETA 00:02
[download] 1.0% of 2.99MiB at 943.80KiB/s ETA 00:03
[download] 2.1% of 2.99MiB at 1.17MiB/s ETA 00:02
[download] 4.1% of 2.99MiB at 1.31MiB/s ETA 00:02
[download] 8.3% of 2.99MiB at 1.59MiB/s ETA 00:01
[download] 16.7% of 2.99MiB at 1.37MiB/s ETA 00:01
[download] 33.4% of 2.99MiB at 1.03MiB/s ETA 00:01
[download] 60.8% of 2.99MiB at 942.47KiB/s ETA 00:01
[download] 88.1% of 2.99MiB at 908.52KiB/s ETA 00:00
[download] 100.0% of 2.99MiB at 897.53KiB/s ETA 00:00
[download] 100% of 2.99MiB in 00:03
MKV
05-05-2017_00:35:15:677036
*****END OF YOUTUBE*****
*****START OF YOUTUBE*****
VIDEO
[download] 0.0% of 41.89MiB at 251.26KiB/s ETA 02:55
[download] 0.0% of 41.89MiB at 612.01KiB/s ETA 01:10
[download] 0.0% of 41.89MiB at 1.23MiB/s ETA 00:34
[download] 0.0% of 41.89MiB at 2.33MiB/s ETA 00:18
[download] 0.1% of 41.89MiB at 783.21KiB/s ETA 00:54
[download] 0.1% of 41.89MiB at 959.46KiB/s ETA 00:44
[download] 0.3% of 41.89MiB at 1.16MiB/s ETA 00:36
[download] 0.6% of 41.89MiB at 1.45MiB/s ETA 00:28
[download] 1.2% of 41.89MiB at 1.15MiB/s ETA 00:35
[download] 2.4% of 41.89MiB at 986.82KiB/s ETA 00:42
[download] 4.4% of 41.89MiB at 912.91KiB/s ETA 00:44
[download] 6.3% of 41.89MiB at 877.92KiB/s ETA 00:45
[download] 8.2% of 41.89MiB at 870.89KiB/s ETA 00:45
[download] 10.2% of 41.89MiB at 865.95KiB/s ETA 00:44
[download] 12.1% of 41.89MiB at 862.33KiB/s ETA 00:43
[download] 14.1% of 41.89MiB at 859.01KiB/s ETA 00:42
[download] 16.1% of 41.89MiB at 857.18KiB/s ETA 00:42
[download] 18.0% of 41.89MiB at 855.34KiB/s ETA 00:41
[download] 20.0% of 41.89MiB at 850.76KiB/s ETA 00:40
[download] 21.9% of 41.89MiB at 850.71KiB/s ETA 00:39
[download] 23.9% of 41.89MiB at 850.61KiB/s ETA 00:38
[download] 25.9% of 41.89MiB at 850.12KiB/s ETA 00:37
[download] 27.8% of 41.89MiB at 849.74KiB/s ETA 00:36
[download] 29.8% of 41.89MiB at 849.08KiB/s ETA 00:35
[download] 31.7% of 41.89MiB at 848.78KiB/s ETA 00:34
[download] 33.7% of 41.89MiB at 846.31KiB/s ETA 00:33
[download] 35.6% of 41.89MiB at 844.42KiB/s ETA 00:32
[download] 37.5% of 41.89MiB at 844.68KiB/s ETA 00:31
[download] 39.5% of 41.89MiB at 844.87KiB/s ETA 00:30
[download] 41.5% of 41.89MiB at 844.76KiB/s ETA 00:29
[download] 43.4% of 41.89MiB at 844.93KiB/s ETA 00:28
[download] 45.4% of 41.89MiB at 844.77KiB/s ETA 00:27
[download] 47.4% of 41.89MiB at 843.37KiB/s ETA 00:26
[download] 49.2% of 41.89MiB at 843.65KiB/s ETA 00:25
[download] 51.2% of 41.89MiB at 843.66KiB/s ETA 00:24
[download] 53.2% of 41.89MiB at 843.50KiB/s ETA 00:23
[download] 55.2% of 41.89MiB at 843.46KiB/s ETA 00:22
[download] 57.1% of 41.89MiB at 843.19KiB/s ETA 00:21
[download] 59.1% of 41.89MiB at 843.22KiB/s ETA 00:20
[download] 61.0% of 41.89MiB at 842.88KiB/s ETA 00:19
[download] 63.0% of 41.89MiB at 843.00KiB/s ETA 00:18
[download] 65.0% of 41.89MiB at 842.80KiB/s ETA 00:17
[download] 66.9% of 41.89MiB at 842.91KiB/s ETA 00:16
[download] 68.9% of 41.89MiB at 842.09KiB/s ETA 00:15
[download] 70.8% of 41.89MiB at 842.40KiB/s ETA 00:14
[download] 72.8% of 41.89MiB at 840.95KiB/s ETA 00:13
[download] 74.6% of 41.89MiB at 840.38KiB/s ETA 00:12
[download] 76.5% of 41.89MiB at 840.77KiB/s ETA 00:11
[download] 78.5% of 41.89MiB at 840.21KiB/s ETA 00:10
[download] 80.4% of 41.89MiB at 840.45KiB/s ETA 00:09
[download] 82.4% of 41.89MiB at 840.65KiB/s ETA 00:08
[download] 84.4% of 41.89MiB at 840.80KiB/s ETA 00:07
[download] 86.4% of 41.89MiB at 840.35KiB/s ETA 00:06
[download] 88.3% of 41.89MiB at 840.73KiB/s ETA 00:05
[download] 90.3% of 41.89MiB at 840.32KiB/s ETA 00:04
[download] 92.2% of 41.89MiB at 840.69KiB/s ETA 00:03
[download] 94.2% of 41.89MiB at 840.31KiB/s ETA 00:02
[download] 96.1% of 41.89MiB at 840.64KiB/s ETA 00:01
[download] 98.1% of 41.89MiB at 840.26KiB/s ETA 00:00
[download] 100.0% of 41.89MiB at 840.32KiB/s ETA 00:00
[download] 100% of 41.89MiB in 00:51
AUDIO
[download] 0.0% of 10.35MiB at 114.98KiB/s ETA 01:32
[download] 0.0% of 10.35MiB at 317.99KiB/s ETA 00:33
[download] 0.1% of 10.35MiB at 694.85KiB/s ETA 00:15
[download] 0.1% of 10.35MiB at 1.37MiB/s ETA 00:07
[download] 0.3% of 10.35MiB at 846.04KiB/s ETA 00:12
[download] 0.6% of 10.35MiB at 1.14MiB/s ETA 00:09
[download] 1.2% of 10.35MiB at 1.29MiB/s ETA 00:07
[download] 2.4% of 10.35MiB at 1.71MiB/s ETA 00:05
[download] 4.8% of 10.35MiB at 2.00MiB/s ETA 00:04
[download] 9.7% of 10.35MiB at 1.17MiB/s ETA 00:07
[download] 17.7% of 10.35MiB at 985.70KiB/s ETA 00:08
[download] 25.3% of 10.35MiB at 940.66KiB/s ETA 00:08
[download] 33.3% of 10.35MiB at 916.90KiB/s ETA 00:07
[download] 41.4% of 10.35MiB at 900.34KiB/s ETA 00:06
[download] 49.3% of 10.35MiB at 885.27KiB/s ETA 00:06
[download] 56.9% of 10.35MiB at 880.58KiB/s ETA 00:05
[download] 65.0% of 10.35MiB at 876.17KiB/s ETA 00:04
[download] 73.0% of 10.35MiB at 868.96KiB/s ETA 00:03
[download] 80.7% of 10.35MiB at 867.56KiB/s ETA 00:02
[download] 88.7% of 10.35MiB at 865.95KiB/s ETA 00:01
[download] 96.7% of 10.35MiB at 862.35KiB/s ETA 00:00
[download] 100.0% of 10.35MiB at 862.21KiB/s ETA 00:00
[download] 100% of 10.35MiB in 00:12
MKV
05-05-2017_00:36:24:569523
*****END OF YOUTUBE*****
*****START OF YOUTUBE*****
VIDEO
[download] 0.0% of 5.30MiB at 188.75KiB/s ETA 00:29
[download] 0.1% of 5.30MiB at 474.99KiB/s ETA 00:11
[download] 0.1% of 5.30MiB at 984.97KiB/s ETA 00:05
[download] 0.3% of 5.30MiB at 1.85MiB/s ETA 00:02
[download] 0.6% of 5.30MiB at 896.97KiB/s ETA 00:06
[download] 1.2% of 5.30MiB at 888.54KiB/s ETA 00:06
[download] 2.3% of 5.30MiB at 1006.45KiB/s ETA 00:05
[download] 4.7% of 5.30MiB at 916.41KiB/s ETA 00:05
[download] 9.4% of 5.30MiB at 863.70KiB/s ETA 00:05
[download] 18.9% of 5.30MiB at 847.73KiB/s ETA 00:05
[download] 34.2% of 5.30MiB at 843.72KiB/s ETA 00:04
[download] 49.7% of 5.30MiB at 840.54KiB/s ETA 00:03
[download] 65.0% of 5.30MiB at 839.77KiB/s ETA 00:02
[download] 80.5% of 5.30MiB at 839.71KiB/s ETA 00:01
[download] 95.9% of 5.30MiB at 839.39KiB/s ETA 00:00
[download] 100.0% of 5.30MiB at 842.74KiB/s ETA 00:00
[download] 100% of 5.30MiB in 00:06
AUDIO
[download] 0.0% of 2.99MiB at 112.61KiB/s ETA 00:27
[download] 0.1% of 2.99MiB at 311.43KiB/s ETA 00:09
[download] 0.2% of 2.99MiB at 682.19KiB/s ETA 00:04
[download] 0.5% of 2.99MiB at 1.32MiB/s ETA 00:02
[download] 1.0% of 2.99MiB at 943.80KiB/s ETA 00:03
[download] 2.1% of 2.99MiB at 1.17MiB/s ETA 00:02
[download] 4.1% of 2.99MiB at 1.31MiB/s ETA 00:02
[download] 8.3% of 2.99MiB at 1.59MiB/s ETA 00:01
[download] 16.7% of 2.99MiB at 1.37MiB/s ETA 00:01
[download] 33.4% of 2.99MiB at 1.03MiB/s ETA 00:01
[download] 60.8% of 2.99MiB at 942.47KiB/s ETA 00:01
[download] 88.1% of 2.99MiB at 908.52KiB/s ETA 00:00
[download] 100.0% of 2.99MiB at 897.53KiB/s ETA 00:00
[download] 100% of 2.99MiB in 00:03
MKV
05-05-2017_00:35:15:677036
*****END OF YOUTUBE*****
實際的文件比這個長。 獲取行塊後,我要計算具有數據的實例數量,例如百分比。就像從視頻到音頻的第一塊一樣,它有17行。
示例輸出
Video to Audio
Count = 17
Audio to MKV
Count = 14
然後再次重複,直到文件的末尾,以便它應該是
最終樣本輸出
Video to Audio
Count = 17
Audio to MKV
Count = 14
Video to Audio
Count = 61
Audio to MKV
Count = 23
你能證明你期望得到的輸出的例子嗎? – Tim
@Tim您好我編輯我的帖子,以便您可以看到示例輸出。 –