我有一個巨大的文件,該文件是這樣的:閱讀3號線然後每
Name: Block of line 1
Data: Block of line 2
**Important line 3**
Not important line 4
Not important line 5
**Another important line 6**
Not important line 7
Name: Block of line 1
Data: Block of line 2
**Important line 3**
Not important line 4
Not important line 5
**Another important line 6**
Not important line 7
Name: Block of line 1
Data: Block of line 2
**Important line 3**
Not important line 4
Not important line 5
**Another important line 6**
Not important line 7
在蟒蛇我想讀每一個第3和第6行或當我使用.read(),它應該使2號線和5
我的代碼只打印第一個塊,所以我非常希望遍歷它:
files = open(fo, 'r')
for i, line in enumerate(files):
if i == 2:
print line
elif i == 5:
print line
break
更多imformations將是有益的。哪種語言?你有什麼嘗試? – Pr0gr4mm3r
對不起,在python中。目前我只能第一次打印,但似乎無法找到一種方法來循環播放,並在文件結束之前繼續播放我想要的內容。希望這可以清除事情。 – Chino